The simplest React.js state management library which coexists with Redux
Decorator + Reducer
ALERT
You need to download babel plugin @babel/plugin-proposal-decorators
//in webpack.config.js //the order should be identical "@babel/plugin-proposal-decorators" "legacy":true "@babel/plugin-proposal-class-properties" "loose": true module: rules: test: /\.$/ exclude: // use: loader: 'babel-loader' options: presets: '@babel/preset-env'"@babel/preset-react" plugins:"@babel/plugin-proposal-object-rest-spread" "@babel/plugin-transform-runtime" "helpers": true "babel-plugin-styled-components" "@babel/plugin-proposal-decorators" "legacy":true "@babel/plugin-proposal-class-properties" "loose": true "@babel/plugin-syntax-jsx" "@babel/plugin-transform-classes"
//in index.js; //custom reducersconst firstReducer = { } const secondReducer = { } const reducers = const store = ReactDOM;
//in App.jsx;; @ //dispatch an action @event { //pass an object like redux action creator return type:"INC"payload:5 } //listen a state change which happens in child component @listen { //if state is empty, render nothing ifObjectlength === 0 return const text = state; return <p>text</p> } { return <div> <button onClick=thisonClick>Click to increase number</button> <AppChild/> this </div> }
//in AppChild.jsx;; @ //dispatch an action @event { //pass an object like redux action creator return type:"SCREAM" } //listen a state change which happens in parent component @listen { //if state is empty, render nothing ifObjectlength === 0 return const number = state; return <p>number</p> } { return <div> <button onClick=thisonClick>Click to change text</button> this </div> }