PropTypes
Валидаторы
Дополнительно
There are validators for node and element. A node is anything that can be rendered, meaning numbers, strings, elements, or an array of those. An element is a React element created with JSX or by
calling React.createElement.
keys - ключи
!!! keys should be stable, permanent, and unique for each element in the array
- stable - у элемента всегда одинаковый key независимо от его позиции в массиве
- permanent - ключ не меняется между рендерами
- unique - не может быть двух элементов с одинаковым ключом
setState
2 способа обойти асинхронность setState
1. callback function
2. Functional setState
Что хранить в стейтах
As a general rule, data that is stored in state should be referenced inside render somewhere. Component state is for storing UI state – things that affect the visual rendering of the page. This makes sense
because any time state is updated, the component will re-render.
If modifying a piece of data does not visually change the component, that data shouldn’t go into state.
Here are some things that make sense to put in state:
• User-entered input (values of text boxes and other form fields)
• Current or selected item (the current tab, the selected row)
• Data from the server (a list of products, the number of “likes” on a page)
• Open/closed state (modal open/closed, sidebar expanded/hidden)