react-rest-state
v1.2.0
Published
state managment
Downloads
43
Maintainers
Readme
react-rest-state
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>;
}