npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app
npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app
I've recently ran into a pitfall of [React.memo()
][memo] that seems generally overlooked; skimming over the top results in Google just finds it mentioned in passing in a [React issue][regit], but not in the [FAQ] or API [overview][react-api], and not in the articles that set out to explain React.memo()
(at least the ones I looked at). The issue is specifically that nesting children defeats memoization, unless the children are just plain text. To give a simplified code example:
const Memoized = React.memo(({ children }) => (<div>{children}</div>));
// Won't ever re-render
<Memoized>bar</Memoized>
// Will re-render every time; the memoization does nothing
kill -9 $(lsof -i:PORT -t) 2> /dev/null |
import { race, cancel, take, fork, all, put, select } from 'redux-saga/effects'; | |
export function* fetchDataForPage() { | |
const userId = yield select(getUserId); | |
try { | |
if (!userId) { | |
throw new Error('No user - aborting'); | |
} |
If you use server rendering, keep in mind that neither useLayoutEffect
nor useEffect
can run until the JavaScript is downloaded.
You might see a warning if you try to useLayoutEffect
on the server. Here's two common ways to fix it.
If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect
instead.
function MyComponent() {
var scores = [1, 4, 6, 8]; | |
var result = scores.reduce((total, score) => total + score) / scores.length; | |
console.log(result); // 4.75 |
/* | |
* Clearfix | |
*/ | |
clearfix() | |
&:before, | |
&:after | |
content ' ' | |
display table | |
&:after |