简体   繁体   中英

How can I refresh React Functional component?

Now I'm using React Functional Component and going to display about variable.

let bundles_data = [];
const SelectExistNFCType = (props) => {
   const setAdd = async () => {
       ...
        data.map((value, index) => {
            bundles_data.push(value)
        })
        ...
    }
}

I tried to display bundles_data's value when calling setAdd function. Now the bundles_data is changing, but can't display immediately. Is there any solution?

Please the state of React.

const SelectExistNFCType = (props) => {
   const [bundlesData, setBundlesData] = React.useState([]);
   const setAdd = async () => {
        ...
        data.map((value, index) => {
            setBundlesData([...bundlesData, value]);
        })
        ...
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM