Skip to content

Bug: state could be reset into the initialValue when using StrictMode #19103

Closed
@theKashey

Description

@theKashey

React version: 16.13.1

Steps To Reproduce

  1. Wrap application with StrictMode
  2. use useState
  3. sometimes value would be reset to the initial

Link to code example: https://codesandbox.io/s/react-stripe-js-z79qw?file=/src/index.js

There are two cases, one is not working in StrictMode and one works well. Without strick mode both works. Console output is empty.

We actually found the buggy behaviour in stripe-js/react - it uses useState to save the context value.
And it is (not) working this way:

In the same time:

The current behavior

I've failed to understand the current behavior - there is a case (we know one) when state is reset, while there are many cases where everything is working as expected.

The expected behavior

State should be always preserved; StrictMode should have to effect on hooks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions