Why doesn"t react automatically generate key, for lists instead of developers writing their own key?
The uniqueness ofreact generated by itself can be guaranteed, is it because the stability of key cannot be guaranteed?
Why doesn"t react automatically generate key, for lists instead of developers writing their own key?
The uniqueness ofreact generated by itself can be guaranteed, is it because the stability of key cannot be guaranteed?
because the stability of key cannot be guaranteed
because the content can be changed, but id cannot be changed, otherwise the rendering efficiency will be reduced
because the criterion of "uniqueness" is in the hands of the user, React cannot automatically judge it. For example, I can use age to generate a list for key, or I can distinguish it by sex. Where can React automatically get such information?
it would be very expensive to calculate key based on the Props of each element.
if you randomly generate an independent key each time, it is equivalent to no key, and it takes more time to generate key.
react
doesn't know which one is the only one? Did you say index
? What if I delete or insert an element in the middle? guid
, severely degrades performance, causing react's reconciliation algorithm
to be useless at all. So will react use guid by default? It's impossible. this article is an old version: https://codeshelper.com/a/11.
look at the plug-in content of react in chrome and you can see that it has its own internal way.
to put it simply: child elements (or components) in the array-Children in an array
key is designed for developers. It is an auxiliary react to make more stable add, change, delete operations.
reference: https://reactjs.org/docs/list.
key is already very troublesome. I think I need to customize what can be key and what can't be done in the future unless it is necessary. The Fragment component in v16.2.0 can automatically add key.
2017.9 has been announced in advance:
Starting with React 16.2.0, we are adding support for a special
fragment syntax to JSX that doesn't require keys.
reference: https://reactjs.org/blog/2017.
how does react ant use custom form validation? 1. Code const Login = ( { loading, dispatch, form: { getFieldDecorator, validateFieldsAndScroll }, } ) => { function handleOk() { validateFieldsAndScroll((error...
simply write a project with ant-design-pro, and write a server.js and npm run build packaged file in the root directory with the built-in mock API,. The dist directory is as follows: server.js: server.js302Cannot read property notifyCount of unde...
take websites made of Vue as an example. Baimi Wallet https: www.bmqb.com a safety( website comes from the sponsor of the official Vue.js website) brief Nuggets. I don t know why. I always feel that these vue sites can be seen at a glance that...
this occurs as soon as the background of node is opened and the front end is refreshed. node: in this case, it is OK to turn off node before refreshing. The agent has successfully obtained the data. I opened the front end first, and then the nod...
an expandable and shrinking react component. Inside the component, there is a button to switch between shrinking and expanding, and pull down, pull up and expand in the internal support of the component, and throw onChange events when changing . how to...