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.
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