react.dart icon indicating copy to clipboard operation
react.dart copied to clipboard

components lose properties

Open Andersmholmgren opened this issue 9 years ago • 2 comments

In https://github.com/danschultz/react.dart/blob/master/lib/src/react/factory.dart#L58 the properties are removed. This causes failure when state is updated and the component tries to render but has no properties.

Was this a copy pasta error or is there something I'm missing?

I removed it locally and it fixes the problem for me. I'll PR if you confirm

Andersmholmgren avatar Nov 19 '15 22:11 Andersmholmgren

Was this a copy pasta error or is there something I'm missing?

No, this was just a scenario that wasn't fully thought out. This line prevents a memory leak by removing the props that are needed for the lifecycle js-interop calls when a component is rendered.

A proper fix would be to have componentWillUpdate store the "previous props" somewhere, so that it's available in componentDidUpdate. One approach is to introduce a new Component._update(props, state) method that's called from componentWillUpdate, This would set Component._props, Component._state, and a new Component._prevProps field. Then you could access Component._prevProps from componentDidUpdate.

danschultz avatar Nov 20 '15 02:11 danschultz

Unfortunately, my innovation week has ended so I'll drop this for a while.

I am making do with the workaround https://github.com/Andersmholmgren/react.dart/tree/workaround_for_missing_props for now

Andersmholmgren avatar Nov 21 '15 00:11 Andersmholmgren