Managing state with React Context

By DEV Community - 2020-10-14

Description

In my previous post I was writing about using Redux with React for the state management. This blog po...

Summary

  • In my previous post I was writing about using Redux with React for the state management.
  • But when application become larger, certain types of props (e.g.
  • locale preference, UI theme) that are required by many components within an application, should be passed down from top to bottom through the components which doesn't even need them.
  • The value argument passed to the function will be equal to the value prop of the closest Provider for this Context.
  • Thank you for pointing out that JSX nesting can be solved with Redux, it's very useful :) If you use redux only to avoid a lot of Providers then I don't see the point, I mean I have lots of providers and for me Context makes my codebase cleaner and Redux makes my whole project look like a mess.

 

Topics

  1. Frontend (0.39)
  2. Backend (0.16)
  3. Management (0.12)

Similar Articles

sudheerj/reactjs-interview-questions

By GitHub - 2021-01-12

List of top 500 ReactJS Interview Questions & Answers....Coding exercise questions are coming soon!! - sudheerj/reactjs-interview-questions

React Hooks Cheatsheet: The 7 Hooks You Need To Know

By freeCodeCamp.org - 2021-02-08

This new tutorial will show you everything you need to know about React Hooks from scratch. I've put this cheatsheet together to help you become knowledgeable and effective with React Hooks as quickly ...

When a simple React context gets out of hand.

By DEV Community - 2021-01-28

It seemed like a good idea to start. Separate state into different "contexts". Just use `useState`. Then, `useEffect` and multiple if branches snuck in and it became a nightmare.

A Thoughtful Way To Use React’s useRef() Hook

By Smashing Magazine - 2020-11-19

In a React component, useState and useReducer can cause your component to re-render each time there is a call to the update functions. In this article, you will find out how to use the useRef() hook t ...