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, clean and well structured state management library for react
Basic usage example
Note: This is a usage example of sharing data between parent and a direct child, but keep in mind that the child could have been a nested child and everything would have stayed the same.
importReact,{Component}from'react';import{observer}from'controllerim';import{ParentController}from'./ParentController';classParentextendsComponent{componentWillMount(){this.controller=newParentController(this);}render(){return(<div><h1>{this.controller.getMessage()}</h1><Child/><buttononClick={()=>this.controller.setMessage('hello world!')}>Click me to change message</button></div>);}};exportdefaultobserver(Parent);/** note: If you don't want to use default export, you could export the class directly:export const Parent = observer( class extends Component { ... });*/
Inside Child.jsx:
importReact,{Component}from'react';import{observer}from'controllerim';import{ChildController}from'./ChildController';classChildextendsComponent{componentWillMount(){this.controller=newChildController(this);this.parentController=this.controller.getParentController('ParentController');}render(){return(<div><span>This is a message from parent: {this.parentController.getMessage()}</span></div>);}};exportdefaultobserver(Child);
The text was updated successfully, but these errors were encountered:
https://github.com/Niryo/controllerim
Basic usage example
Note: This is a usage example of sharing data between parent and a direct child, but keep in mind that the child could have been a nested child and everything would have stayed the same.
Inside
ParentController.js
:Inside
Parent.jsx
:Inside
Child.jsx
:The text was updated successfully, but these errors were encountered: