React's setState method with prevState argument

后端 未结 4 1062
野的像风
野的像风 2020-12-15 05:57

I\'m new to React, just have a question on setState method. Let\'s say we have a component:

class MyApp extends React.Component {

  state = {
    count: 3
          


        
4条回答
  •  情书的邮戳
    2020-12-15 06:42

    here iseveryone know just state:prevstate.counter+1.. we can also do this with state:this.state.counter+1. This is not the way i think to use prevstate. i have problem in array when i push into existing state it allow me but second time it prevent changes

提交回复
热议问题