https://github.com/dabapps/react-set-props
Store arbitrary state in redux with a similar API to setState
https://github.com/dabapps/react-set-props
Last synced: 9 months ago
JSON representation
Store arbitrary state in redux with a similar API to setState
- Host: GitHub
- URL: https://github.com/dabapps/react-set-props
- Owner: dabapps
- License: mit
- Created: 2017-10-21T11:33:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-30T10:51:50.000Z (over 7 years ago)
- Last Synced: 2025-04-06T11:47:12.750Z (about 1 year ago)
- Language: TypeScript
- Size: 220 KB
- Stars: 2
- Watchers: 21
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# react-set-props
[](https://travis-ci.org/dabapps/react-set-props)
**Store arbitrary state in redux with a similar API to setState**
## Installation
```shell
npm install @dabapps/react-set-props --save --save-exact
```
## Usage
### TypeScript
#### Connecting your component
```tsx
import { withSetProps, SetPropsInterface } from '@dabapps/react-set-props';
interface ExternalProps {
buttonText: string;
}
interface Props {
count: number;
}
const MyComponent = ({buttonText, count, setProps}: ExternalProps & SetPropsInterface) => (
Count: {count}
setProps({count: count + 1})}>
{buttonText}
);
const getInitialProps = (props: ExternalProps) => ({
count: 0
});
export default withSetProps(getInitialProps)(MyComponent);
```
#### Props reducer
```tsx
import { setPropsReducer } from '@dabapps/react-set-props';
combineReducers({
setPropsReducer
});
```
### Javascript
#### Connecting your component
```js
import { withSetProps } from '@dabapps/react-set-props';
const MyComponent = ({buttonText, count, setProps}) => (
Count: {count}
setProps({count: count + 1})}>
{buttonText}
);
const getInitialProps = (props) => ({
count: 0
});
export default withSetProps(getInitialProps)(MyComponent);
```
#### Props reducer
```js
import { setPropsReducer } from '@dabapps/react-set-props';
combineReducers({
setPropsReducer
});
```
## Code of conduct
For guidelines regarding the code of conduct when contributing to this repository please review [https://www.dabapps.com/open-source/code-of-conduct/](https://www.dabapps.com/open-source/code-of-conduct/)