Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how useReducer works

# react
import "./styles.css";
import React, { useReducer } from "react";

function redcuer(state, action){
  return { count: state.count + 1 }
}

export default function App() {
  const [state, dispatch] = useReducer(redcuer, { count: 0 })

  function decrement(){

  }
  function increment(){
    dispatch()
  }
  return (
    <div className="App">
      <button onClick={decrement}>-</button>
      <span>{state.count}</span>
      <button onClick={increment}>+</button>
    </div>
  );
}
Source by www.delftstack.com #
 
PREVIOUS NEXT
Tagged: #useReducer #works
ADD COMMENT
Topic
Name
4+1 =