Context
WebComp's Context is a way to manage a shared state across components
Using Context
1. Import context
import { WebComponent, register } from '@webcomp/core'
import withContext from '@webcomp/context'2. Wrap your component in withContext before registering
withContext before registeringclass SideBarComponent extends WebComponent {
render(props) {
return (
<aside>
<img src="" />
<span className="username">@</span>
</aside>
);
}
}
// Provide a name for the context
const SideBar = withContext('user-data')(SideBarComponent)
register(SideBar, 'side-bar')3. Get context from props
Initial context value
Second argument in withContext
withContextgetInitialContext static method
getInitialContext static methodLast updated
Was this helpful?