@dabapps/react-set-props

Store arbitrary state in redux with a similar API to setState

Stats

StarsIssuesVersionUpdatedCreatedSize
@dabapps/react-set-props
211.2.03 years ago4 years agoMinified + gzip package size for @dabapps/react-set-props in KB

Readme

react-set-props

Build Status

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
});

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.