react useReducer
admin
2024-03-02 20:01:16

useReducer():Action钩子

import React, {useReducer} from 'react'

export default function UseReducer() {

const reducer = (state, action) => {

switch (action.type) {

case 'add':

return {count: state.count + 1};

default:

return {count: state.count};

}

}

const [state, dispatch] = useReducer(reducer, {count: 0})

const addcount = () => {

dispatch({

type: 'add'

})

}

return (

{state.count}

)

}

相关内容

热门资讯

巡湘记荣登2025第九届中华餐... 2025年11月13日,上海新国际博览中心见证了餐饮界的一场盛会——“2025第22届中华餐饮双创论...
一盘椰子酥烘焙出生活甜香 周末的午后,阳光透过烤箱玻璃洒进厨房,母亲正将揉好的面团擀成薄片,空气中弥漫着黄油与椰蓉的香甜气息。...
映在五角枫林里的京蒙协作情 初冬的内蒙古科尔沁草原银装素裹,一片静谧。刚刚忙活了一秋的牧民吴双龙,高兴地给记者算起账来:“以前守...
映在五角枫林里的京蒙协作情 映...   初冬的内蒙古科尔沁草原银装素裹,一片静谧。刚刚忙活了一秋的牧民吴双龙,高兴地给记者算起账来:“以...