class Person extends Component {
render() {
noWay(args ) {
}
ohYes = (args) => {
const {dispatch} = this.props //HANDY!
}
return (
<div content>
<button onClick={noWay.bind(this)} />
<button onClick={ohYes} />
</div>
);
}
}
export default withRouter(
connect(function(state) {
return {
user: state.user
};
})(User)
);
@withRouter
@connect(connectToState)
@withStyles(styles)
export default class Submission extends Component {
export const withSomething = ComposedComponent =>
class extends Component {
state = {
something: null,
fetching: false
};
somethingPromise= null;
componentDidMount() {
const ctx = this;
if (ctx.somethingPromise) {
ctx.setState({
fetching: true
});
ctx.somethingPromise.then(something=> {
ctx.setState({
something: something,
fetching: false
});
});
}
}
componentWillMount() {
if (!this.state.something) {
this.somethingPromise= getSomething();
}
}
render() {
return (
<ComposedComponent
{...this.props}
something={this.state.something}
fetching={this.state.fetching}
/>
);
}
};
@withSomething
export default class Whatever extends Component
const reducers = {
UPDATE_WHO: (state, value) => {
return {...state, ...value};
},
UPDATE_WHO_FIRSTNAME: (state, value) => {
return { ...state, ...{ firstname: value } };
},
UPDATE_WHO_LASTNAME: (state, value) => {
return {...state, ...{ lastname: value } };
},
};
const who = (state = {}, action) => {
if (reducers[action.type]) {
return reducers[action.type](state, action.value);
}
return state;
};
export who
function who(state = 0, action) {
switch (action.type) {
case 'UPDATE_WHO':
return {...state, ...action.value}
case 'UPDATE_WHO_FIRSTNAME':
return {...state, ...{ lastname: action.value } }
case 'UPDATE_WHO_LASTNAME':
return {...state, ...{ lastname: action.value } }
default:
return state
}
}
export who