1.0.5 • Published 5 years ago

rctx v1.0.5

Weekly downloads
13
License
-
Repository
github
Last release
5 years ago

Rctx

Example

//Test component
import { importContexts } from 'rctx';
import TestContext from './test-context.ctx';
const TestComponent = props => {
  const { testContext } = props;
  const { add } = testContext;
  return <div onClick={add}>hello world</div>;
};
export default injectContexts(TestComponent, {
  testContext: TestContext
});
	//Test Context
import { ContextComponent createContext ContextStore } from  'rctx';
class  TestContext  extends  ContextComponent{
	state = {value:0}
	add  = () => {
		this.setState(prevState  => {
			return { value:  prevState.value  +  1 };
		});
	}
   }
export  default  createContext(TestContext, { store:  new  ContextStore() /*If you want to preserve the state when component unmount*/ });
//App
import TestContext from './test-context.ctx';
import { importContexts } from 'rctx';
class App extends Component {
  render() {
    return <TestComponent />;
  }
}

export default importContexts(App, [TestContext]);
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago