You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Simple implementation of react context for sharing an object between components without causing unnecessary rendering
Usage
// Initial value is Required!constinitialValue={lang: 'en',color: 'dark',firstVisit: null}// "createObjectContext" - This is where the magic happensconstExampleContext=createObjectContext(initialValue)// You can now wrap your components as you normally wouldconstParentComponent=()=>{constlang='he'constcolor='light'constfirstVisit=truereturn(<ExampleContext.Providervalue={{ lang, color, firstVisit }}><ChildComponent/></ExampleContext.Provider>)}constChildComponent=()=>{// Select only the properties you want to useconst{ color, lang }=ExampleContext.use('color','lang')return(<div>The color is {color}, and the language is {lang}</div>)}
About
A Simple implementation of react context for sharing an object between components without causing unnecessary rendering