Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does react dva change state

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how react dva changes state, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

React dva changes the state method: 1, create DvaState.js and dvaState.js files; 2, enter the code as "import React from 'react';import {connect} from.}".

The operating environment of this paper: Windows7 system, react17.0.1, Dell G3.

Click on the react dva framework to modify the value of state similar to this.state and this.setState () in react.

Show me first.

Click to change the value of state before

The change of the value of state after clicking change

First, the creator has two files.

DvaState.js under the routes directory

Import React from 'react';import {connect} from' dva';import {Link} from 'dva/router' Let count = 0const DvaState = ({dispatch, dvaState,}) = > {const {dataList} = dvaState console.log (dataList) console.log (dvaState) const handleChangeState = () = > {dispatch ({type:'dvaState/changeState', payload: {dataList: [{list1: count++, list2: 'list22', list3:' list33'}) {list2:'111'}]}})} return (

DvaState {dataList [0] .list1} change state

);}; export default connect (({dvaState}) = > ({dvaState})) (DvaState)

DvaState.js under the models directory

Export default {namespace: 'dvaState', state: {dataList: [{list1:'a', list2:'c',}]}, subscriptions: {setup ({dispatch, history}) {},}, effects: {}, reducers: {changeState (state, {payload}) {return {... state,. Payload}},} Thank you for reading this article carefully. I hope the article "how to change state in react dva" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report