Front-end team lead
Oslo Market Solutions
espen_dev
esphen
function FooComponent({ loggedIn }) {
let sidebarContent;
if (loggedIn) {
sidebarContent = (
<div>
I'm sorry Dave, I'm afraid I can't do that
</div>
);
}
if (!loggedIn) {
sidebarContent = (
<div>
Welcome
</div>
);
}
return (
<aside>
{sidebarContent}
</aside>
);
}
const FooComponent = ({ loggedIn }) => (
<aside>
{loggedIn && (
<div>
I'm sorry Dave, I'm afraid I can't do that
</div>
)}
{!loggedIn && (
<div>
Welcome
</div>
)}
</aside>
);
const FooComponent = ({ loggedIn }) => (
<aside>
{loggedIn && renderLoggedInView()}
{!loggedIn && <LoggedOutMessage />}
</aside>
);
const FooComponent = () => (
<Link to={'/trader/news'}>
To the place
</Link>
);
const FooComponent = () => (
<Link to="/trader/news">
To the place
</Link>
);
const FooComponent = ({ values: { SECTOR, LONG_NAME }}) => (
<h2>
{`${SECTOR}: ${LONG_NAME}`}
</h2>
);
const FooComponent = ({ values: { SECTOR, LONG_NAME }}) => (
<h2>
{SECTOR}: {LONG_NAME}
</h2>
);
const FooComponent = ({ small, location }) => {
const { page } = qs.parse(location?.search, {
ignoreQueryPrefix: true,
});
return (
<Switch location={small && page ? { pathname: `/${page}` } : location}>
...
</Switch>
);
};
const FooComponent = ({ small, location }) => {
const urlQuery = qs.parse(location?.search, {
ignoreQueryPrefix: true,
});
const isOnMobile = small && urlQuery.page;
const currentLocation = isOnMobile
? { pathname: `/${urlQuery.page}` }
: location;
return (
<Switch location={currentLocation}>
...
</Switch>
);
};
const ResponsiveSwitch = ({ small, location, children }) => {
const urlQuery = qs.parse(location?.search, {
ignoreQueryPrefix: true,
});
const isOnMobile = small && urlQuery.page;
const currentLocation = isOnMobile ? { pathname: `/${page}` } : location;
return (
<Switch location={currentLocation}>
{children}
</Switch>
);
};
const FooComponent = () => (
<ResponsiveSwitch>
...
</ResponsiveSwitch>
);
const FooComponent = () => (
<FooContext>
{({ fooValue }) => (
<p>
{fooValue}
</p>
)}
</FooContext>
);
const FooComponent = () => {
const { fooValue } = useContext(FooContext);
return (
<p>
{fooValue}
</p>
);
);
export const useFoo = () => {
return useContext(FooContext);
};
const FooComponent = () => {
const { fooValue } = useFoo();
return (
<p>
{fooValue}
</p>
);
);
const FooComponent = () => {
const isLoggedIn = 'Espen';
return (
<p>
{isLoggedIn}
</p>
);
};
const FooComponent = ({ isLoggedIn }) => {
if (!isLoggedIn) return <LoggedOutMessage />;
return (
<p>
Welcome!
</p>
);
};
const FooComponent = ({ loggedInUser }) => (
<p>
Welcome {loggedInUser.name}!
</p>
);
const array = [...];
const filteredArray = array.filter(...);
const sortedArray = filteredArray.sort(...);
const mappedArray = sortedArray.map(...);
const flattenedArray = mappedArray.flat(2);
const array = [...];
const users = array
.filter(...)
.map(...)
.flat(2);
const sortedUsers = users.sort(...);
const FooComponent = ({ users }) => (
<ul>
{users
.filter(...)
.map(...)
.flat(2)
.sort(...)
.map(...)}
</ul>
);
const filterUsers = users => (
users
.filter(...)
.map(...)
.flat(2)
.sort(...)
);
const FooComponent = ({ users }) => (
<ul>
{filterUsers(users).map(...)}
</ul>
);
const FooComponent = ({ type }) => (
<div>
{type === 'user' && <UserTable />}
{type === 'admin' && <AdminTable />}
</div>
);
const FooComponent = ({ type }) => (
<>
<Table type="user" />
<Table type="admin" />
</>
);
const Table = ({ type }) => (
<table>
<thead>
<tr>
<th>{type === 'user' ? 'Brukernavn' : 'Admin-navn'}</th>
...
</tr>
</thead>
...
</table>
);
import request from 'superagent';
request
.get('https://vg.no')
.then(function(response) {
console.log(response.body);
});
async function() {
const response = await fetch('https://vg.no');
console.log(await response.json());
}
$ git commit -am "ABC-123 ABC-124 ABC-125 Fix bugs"
$ git add file1
$ git commit -m "ABC-123 Solves button responsiveness"
$ git add file2
$ git commit -m "ABC-124 Fixes link target"
$ git add file3
$ git commit -m "ABC-125 Upgrades moment version to 3.2"
$ git add file1
$ git commit -m "ABC-123 Fixes performance issues on portfolio page
This happened because iPhones expose a special API called
Steve that makes it overheat when exposed to bad design.
Fixed by using the newer Tim API which doesn't seem to care"
<label
htmlFor="file"
className={`file ${this.checkValidationErrors('date')}`}
>
Fil:
<input
className={styles.file}
type="file"
name="file"
accept=".pdf"
placeholder="Klikk for å velge fil"
onChange={this.handleFileChange}
/>
{/* <FileInput name="file"
accept=".pdf"
placeholder="Klikk for å velge fil"
onChange={ this.handleFileChange }
/> */}
</label>
https://slides.com/esphen/react-patterns