npm.io
1.0.9 • Published 5 years ago

simple-redux-ts

Licence
ISC
Version
1.0.9
Deps
3
Size
5 kB
Vulns
0
Weekly
0

Redux React Simple

Simple Configuration Redux

N|Solid

Setup Redux

yarn add simple-redux-ts

Then

  • Add file to root/src project
  • src/state.json

Example :

{
    "value": 6
}

Example:

Add script to head index.ts/js

...
...
import { creteStore, Provider } from 'simple-redux-ts';
...
ReactDOM.render(
    <Provider store={creteStore()}>
        <App />
    </Provider>
, document.getElementById('root'));

Other Component

Use this.props.updateState({ ... }) Access value with this.props.value

import React, { Component } from 'react';
import { connects } from 'simple-redux-ts';
...
...
class App extends Component {
    ...
    ...
    render() {
        return (
            ...
            ...
            <button onClick={() => {
                this.props.updateState({
                    value: this.props.value - 1
                });
            }}>Min</button>
            
            <div>{this.props.value}</div>
            
            <button onClick={() => {
                this.props.updateState({
                    value: this.props.value + 1
                });
            }}>Plus</button>
            ...
            ...
        );
    }
    ...
    ...
}
export default connects(App);

Features

  • One Function for update all props
  • Use props.updateState({ ... })

Keywords