enzymejs/enzyme

getDerivedStateFromProps called from setState

Open

#2078 opened on Apr 2, 2019

View on GitHub
 (2 comments) (3 reactions) (0 assignees)JavaScript (19,979 stars) (2,016 forks)batch import
bughelp wanted

Description

Current behavior

getDerivedStateFromProps is being called from within setState, instead of before render, which overwrites the state and is inconsistent with react behavior. Please see attached codesandbox. There is a FloatInput.spec.js file with a unit test to show the behavior.

Expected behavior

getDerivedStateFromProps should be called before render not from setState.

Your environment

https://codesandbox.io/s/vqrm0r0r30

API

  • [x ] shallow
  • mount
  • render

Version

library version
enzyme 3.9.0
react 16.8.3
react-dom 16.8.3
react-test-renderer
adapter (below)

Adapter

  • [x ] enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

Contributor guide