React contexts is a very cool feature, and extremely practical to use with the hooks API. You’ve surely met some, and probably recognize them right way.

Today I’d like to share what I learned when creating my own React contexts: **what I consider to be a good context **and how to write one.

There’s another exploration I’d like to share later that won’t be in this post: how and when to split a context in 2 or more.

Let’s dive

Image for post

Le awesome dive

Let’s take the example of a Theme context, providing a mode: 'dark' or 'light', and a compact boolean to indicate whether the UI should have reduced margins and paddings or not.

#react-hook #javascript #typescript #react

React: How I learned to create optimized contexts
2.20 GEEK