@dabapps/react-set-props
v1.2.0
Published
Store arbitrary state in redux with a similar API to setState
Downloads
20
Readme
react-set-props
Store arbitrary state in redux with a similar API to setState
Installation
npm install @dabapps/react-set-props --save --save-exact
Usage
TypeScript
Connecting your component
import { withSetProps, SetPropsInterface } from '@dabapps/react-set-props';
interface ExternalProps {
buttonText: string;
}
interface Props {
count: number;
}
const MyComponent = ({buttonText, count, setProps}: ExternalProps & SetPropsInterface<Props>) => (
<p>
Count: {count}
<button onClick={() => setProps({count: count + 1})}>
{buttonText}
</button>
</p>
);
const getInitialProps = (props: ExternalProps) => ({
count: 0
});
export default withSetProps<Props, ExternalProps>(getInitialProps)(MyComponent);
Props reducer
import { setPropsReducer } from '@dabapps/react-set-props';
combineReducers({
setPropsReducer
});
Javascript
Connecting your component
import { withSetProps } from '@dabapps/react-set-props';
const MyComponent = ({buttonText, count, setProps}) => (
<p>
Count: {count}
<button onClick={() => setProps({count: count + 1})}>
{buttonText}
</button>
</p>
);
const getInitialProps = (props) => ({
count: 0
});
export default withSetProps(getInitialProps)(MyComponent);
Props reducer
import { setPropsReducer } from '@dabapps/react-set-props';
combineReducers({
setPropsReducer
});