Monday, October 24, 2022

12/365 React Context

 Today in the Meta Frontend Developer Course I learned about React Context. Context in React is a way of having props that are accessible everywhere in your app. This solves a problem known as "prop drilling" where you have to pass props through a long chain of parent and child components. Context eliminates the need for prop drilling and allows certain global props to be accessible everywhere. One of the common uses for context is for an app theme, like light and dark mode for example. This way when the theme prop is toggled, the context provides the prop to any component that needs it and they can render themselves accordingly. However, the best practice is to keep your context as lean as possible and only use it when it really makes sense for the app design.

No comments:

Post a Comment

190: Sablier

 The CodeHawks platform has an upcoming audit on the Sablier protocol, so I decided to read through the docs and familiarize myself with the...