React render is rendered twice, one is the original state data, and the other is the newly acquired data

Time:2021-2-1

There is a problem in the project. After the dispath action, the render will render the data of the state twice, one is the original state, and the other is the newly acquired state, as shown in the figure below
React render is rendered twice, one is the original state data, and the other is the newly acquired data
React render is rendered twice, one is the original state data, and the other is the newly acquired data
React render is rendered twice, one is the original state data, and the other is the newly acquired data
This is because the react rendering mechanism causes the original state data to be automatically obtained before the build mount, that is, before the component didmount life cycle. After the component didmount, the state change cannot be obtained again
After all kinds of climbing holes Google, I see a good idea
React render is rendered twice, one is the original state data, and the other is the newly acquired data
After judging whether it is componentdidmount in the state of private component, change the value of state in componentdidmount and select display in render
React render is rendered twice, one is the original state data, and the other is the newly acquired data
React render is rendered twice, one is the original state data, and the other is the newly acquired data

Recommended Today

CentOS modify MariaDB database file storage path

Modify MariaDB database file storage path mysqlIt is also a similar configuration.MariaDBThe default data storage directory is/var/lib/mysql, ready to change to/data/mysql。 Out of Service systemctl stop mariadb data migration mv /var/lib/mysql /data/mysql Modify configuration vim /etc/my.cnf #Add in [client server] socket=/data/mysql/mysql.sock #Add in [mysqld], the end must be/ datadir=/data/mysql/ Full configuration # # This group […]