admin管理员组文章数量:1420659
I'm implementing a multi-step process in React-native (similar to react).
I have a function that determines which step is displayed :
renderStep = step => {
switch (processStep[step]) {
case 0:
return (
<Product />
);
break;
case 1:
return (
<Select data={size} />
);
break;
case 2:
return (
<Select data={adresses} />
);
break;
case 3:
return (
<RecapOrder />
);
break;
default:
return null;
}
};
My 2nd et 3rd step are using the same _stepSelect
ponent. It uses the same logic, so i'm using the same ponent.
My issue is : The Select
ponent doesn't Unmount between the step 1
and 2
even if the props changes.
So my local State is not reset when changing from step 1 to step 2.
How can i force the Component to be Unmounted.
I'm implementing a multi-step process in React-native (similar to react).
I have a function that determines which step is displayed :
renderStep = step => {
switch (processStep[step]) {
case 0:
return (
<Product />
);
break;
case 1:
return (
<Select data={size} />
);
break;
case 2:
return (
<Select data={adresses} />
);
break;
case 3:
return (
<RecapOrder />
);
break;
default:
return null;
}
};
My 2nd et 3rd step are using the same _stepSelect
ponent. It uses the same logic, so i'm using the same ponent.
My issue is : The Select
ponent doesn't Unmount between the step 1
and 2
even if the props changes.
So my local State is not reset when changing from step 1 to step 2.
How can i force the Component to be Unmounted.
Share Improve this question asked Mar 8, 2018 at 15:35 Louis LecocqLouis Lecocq 1,8143 gold badges18 silver badges40 bronze badges 10-
3
A hack I've used is adding a different
key
to the ponents. React uses keys to determine instances of a ponent. So if two ponents have different keys, it should see that as two separate instances. – Chase DeAnda Commented Mar 8, 2018 at 15:38 -
Another (better) solution would be to use the
ponentWillReceiveProps
lifecycle method and handle when newdata
gets passed in the same way you would inponentDidMount
. – Chase DeAnda Commented Mar 8, 2018 at 15:39 - @DimitarChristoff Well no it doesn't. Otherwise i won't be making this issue :) – Louis Lecocq Commented Mar 8, 2018 at 15:42
-
2
@DominicTobias I've never seen anywhere that ponentWillReceiveProps is deprecated. ponentDidUpdate is triggered with any State Changes (props and state). ponentWillReceiveProps is triggered only when new
props
are provided @ChaseDeAnda feel free to provide a concrete answer so i can try it out – Louis Lecocq Commented Mar 8, 2018 at 15:44 - 1 github./facebook/react-native/issues/18175 It not going to be deprecated anytime soon. – Louis Lecocq Commented Mar 8, 2018 at 15:53
1 Answer
Reset to default 10I would suggest first trying to add keys to each element being rendering in this function. I have seen issues where React cannot tell the difference between the ponents being rendered so it skips a few life cycle events and just skips straight to render.
<Product key="process-step-product"/>
本文标签: javascriptReact Switch CaseSame Component doesn39t UnmountStack Overflow
版权声明:本文标题:javascript - React: Switch CaseSame Component doesn't Unmount - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745335892a2654036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论