Need private packages and team management tools?Check out npm Teams »

react-rest-state

1.2.0 • Public • Published

react-rest-state

alt text

NPM

install size dependencies

react-rest-state

easy state managment with high performance

install

npm i react-rest-state --save

use

import { init, state, setState, forceUpdate } from "react-rest-state";
...
init({
  name: "alli"
});
...
console.log(state.name)

setState

setState({ name: "mikel" });

or

setState(prevState => {
  return { name: prevState.name + " mikel" };
});

callback

setState({ name: "mikel" }, () => {
  console.log(state.name);
});

connect

import { connect, state, setState } from "react-rest-state";
 
class app extends React.Component {
  disconnect = connect(
    this,
    ["state1"]
  );
  render() {
    return (
      <View>
        <Text>{state.name}</Text>
        <Button
          title={"change"}
          onPress={() => {
            setState({ name: "jone" });
          }}
        />
      </View>
    );
  }
  componentWillUnmount() {
    this.disconnect();
  }
}

callback

connect(
  this,
  ["name"],
  callbackFunc
);

connect function to states run function when states did update

connect(() => {
  console.log(state.name);
}, ["name"]);

forceUpdate

forceUpdate(["mikel"], callback);

useConnect for Hooks

import { useConnect } from "react-rest-state";
 
function myComponent(props) {
  //if first argumant is a function and runinng when state did update else component will be update
  useConnect(null, ["name"]);
  return <Text>{state.name}</Text>;
}

Install

npm i react-rest-state

DownloadsWeekly Downloads

2

Version

1.2.0

License

ISC

Unpacked Size

65 kB

Total Files

13

Last publish

Collaborators

  • avatar