Skip to main content


Showing posts from April, 2020

The Problem with React's Context API

The problem with context is simple: Everything that consumes a context re-renders everytime that context’s state changes. That means that if you’re consuming your context all over the place in your app, or worse, using one context for your entire app’s state, you’re causing a ton of re-renders all over the place!

function App() {
  return (
      <h2>No Unnecessary Re-renders! 😎</h2>
        <Message />
        <Message />
        <Message />
        <Count />

DND for react - unstated-next

React.useState does not reload state from props

The argument passed to useState is the initial state much like setting state in constructor for a class component and isn't used to update the state on re-render If you want to update state on prop change, make use of useEffect hook functionAvatar(props){const[user, setUser]=React.useState({...props.user