3 ms·
Yes, but in all fairness that’s React 16.8+ (2019) Before that you could write: class Page extends React.Component { componentWillReceiveProps(nextProps
by efortis 1y ago
Yes, but in all fairness that’s React 16.8+ (2019)
Before that you could write:
class Page extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.url !== this.props.url)
logVisit(nextProps.url, this.state.nItems)
}
}
The upcoming `useEffectEvent` will make React even more cryptic and convoluted.
const Page = ({ url }) => {
const onVisit = useEffectEvent(visitedUrl => {
logVisit(visitedUrl, nItems)
})
useEffect(() => {
onVisit(url)
}, [url])
}
- c-hendricks 1y agoReact.Component still exists. And most `useLatest` implementations will get you the advantage of `useEffectEvent` today. If you really wanted to take a jab at React people, show them const that = useLatest({ // bunch of stuff you want to pass around to effects / callbacks })