-
Notifications
You must be signed in to change notification settings - Fork 113
Attempt to improve "Returning state" section #36
Comments
👍 The trick is that I'm working on a solution to this problem right now, and I came up with an render(state, props, updater) {
return (
<div>
<span>Clicked {state.count} times!</span>
<a href="javascript:void(0)"
onClick={updater((e, {props, state, updater}) => {count: state.count + 1})}>
Click to increment!
</a>
</div>
);
} BTW: What syntax is that for default arguments? |
@jordwalke Ah, got it. I also like your way with updater. My goal was to avoid using About the syntax - it's in the ECMA-262 proposal |
what about |
@chicoxyzzy I'd implement a context as one of the arguments: render(state, props, ctx, updater) {
//...
} |
IMO it's better to make render(state = { foo: 0, bar: 'hello' }, props = { length: 100500 }, context = null, updater = defaultUpdater ) {
//...
} |
@chicoxyzzy What means "optional"? If you want, you can omit all attributes, use it like this: render() {
return <div style={{ color: 'red', }}>*</div>;
} If you're talking about order of arguments, then I guess |
I mean that it should be handful to omit some arguments (i.e. |
I think that render should take an object in which you can pass all the parameters. That way you can easily omit all that you don’t need:
|
I don't quite get what would be the purpose of the |
@FezVrasta It's kind of like doing |
How preact achieves it then? Once you have this code, everything should just work:
Still better than:
|
@FezVrasta With the Mutation makes many things more difficult including (eventually) concurrency/parallelism. If you change your example slightly to use the alternative React <button onClick={
(e) => this.setState((prevState, props) => ({ foo: prevState.foo + 1 })
}>
{foo}
</button>; This alternative React
|
What about if we can get rid of
this
:The text was updated successfully, but these errors were encountered: