(精华)2020年7月29日 React react-hooks的useReducer的使用
发布日期:2021-06-29 15:08:27 浏览次数:3 分类:技术文章

本文共 688 字,大约阅读时间需要 2 分钟。

import React , {
useReducer} from 'react'// (state,action)=>newStateconst UseReducer = ()=>{
const reducer = (state,action) =>{
if(action.type === 'add'){
return {
...state, count:state.count+1 } }else{
return state } } const addCount = ()=>{
// dispatch dispatch( {
type:'add' } ) } // 第一项是当前的状态值 第二项是发送action的dispatch函数 const [state,dispatch] = useReducer(reducer,{
count:0}) return (

{

state.count}

)}export default UseReducer

转载地址:https://codeboy.blog.csdn.net/article/details/107649649 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:(精华)2020年7月30日 微信小程序 模块的使用
下一篇:(精华)2020年7月29日 React react-hooks的useEffect的使用

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年04月24日 15时50分26秒