New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proppy: add `onChange` function #4

merged 3 commits into from Jun 2, 2018


1 participant
Copy link

fahad19 commented Jun 2, 2018


onChange(propName, (prop, providers) => props)

(prevProps, nextProps) => true,
(props, providers) => props

Detect a change in props, and return new props.


Change foo, when counter changes:

const P = compose(
  withProps({ foo: 'initial foo value' })
  withState('counter', 'setCounter', 0),
  onChange('counter', (props, providers) => ({
    foo: `changed foo with counter ${props.counter}`

const p = P();
console.log(; // `initial foo value`

console.log(; // `changed foo with counter 10`

Detecting complex changes:

const P = compose(
  withState('counter', 'setCounter', 0),
    // detect
    (prevProps, nextProps) => true,

    // return props
    (props, providers) => props

fahad19 added some commits Jun 2, 2018

@fahad19 fahad19 self-assigned this Jun 2, 2018

@fahad19 fahad19 added PR minor labels Jun 2, 2018

@fahad19 fahad19 merged commit 8da847e into master Jun 2, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
continuous-integration/travis-ci/push The Travis CI build passed

@fahad19 fahad19 deleted the onChange branch Jun 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment