Skip to content

Instantly share code, notes, and snippets.

@stoeffel
Last active September 25, 2015 20:49
Show Gist options
  • Save stoeffel/20d3f9a820304fd25ee0 to your computer and use it in GitHub Desktop.
Save stoeffel/20d3f9a820304fd25ee0 to your computer and use it in GitHub Desktop.
React compose thisless components
import {
compose,
initialState,
didMount
} from 'react';
export const MyComponent = compose(
initialState( () => {
return {
hidden: true
};
},
connectToStores([Store1, Store2]), // higher-order component pattern
didMount( (props, { setState, state }) => {
// do stuff
},
( props, { setState, state } ) =>
<div>
{ /* ... */ }
</div>
)
);
// same as
let Foo = ({ props, { setState, state }}) => (
<div>
{/* ...*/}
</div>
);
Foo = initialState(() => {
return { hidden: true }
}, Foo);
@stoeffel
Copy link
Author

let Foo = ({ { onNext }, { setState, state }}) => {
  const onClick = (event) => onNext(event.target.value);
  return (
    <div>
      <button onClick={onClick}>next</button>
    </div>
    );
}

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