score:3
i solved the problem by adding
switch (action.type) {
case 'set_name':
return { ...state, playername: action.payload }
in my reducer, and in home.js changed the state key i had in there to payload. not 100% sure if it having the same name was effecting anything, but its much less confusing naming it payload.
const handleclick = () => {
if (!isstringempty(playernameentry.current.value)) {
dispatch({ type: 'set_name', payload: playernameentry.current.value });
score:3
wrap the whole app with appcontext.provider passing with state and dispatch, like below
<appcontext.provider value={{ state, dispatch }}>
<div classname="app">
<compo />
</div>
</appcontext.provider>
Source: stackoverflow.com
Related Query
- Dispatch is not a function useContext/useReducer React hooks
- Dispatch is not a function - React Testing Library with React Redux Hooks
- TypeError dispatcher.useState is not a function when using React Hooks
- How to fix nextCreate is not a function setting up useMemo setting up authentication react router and hooks
- React 16.7 Hooks : `react.useState` is not a function
- React Hooks issues in React 16.7 TypeError: Object(...) is not a function
- React hooks value is not accessible in event listener function
- How to test react useContext useReducer dispatch in component
- TypeError: Object(...) is not a function while using React Hooks
- useSelector function is not updating the state of after dispatch function -react hooks
- React Hooks state not working properly when the function calling it is called in another function
- Type Error "Map" is not a function while using react hooks
- React hooks not returning updated state values inside callback function from library events (FabricJS)
- React hooks updated state not passed to function
- dispatch with UseReducer and useContext hooks: dispatch does not exist on type {}
- React Hooks setState function not setting state
- React hooks map is not a function
- Dispatch is not a function react redux
- TypeError: setCartCount is not a function - React Hooks - Redux
- React Hooks useContext not allowing state change
- How to wrap React Hooks dispatch into function outside component
- Formik hooks "useField" throws error stating that the component is not a React function component
- 'dispatch' is not defined when using useReducer with useContext in react
- How to make a reusable function that calls setUserContext? React Hooks useContext
- useReducer and useContext Dispatch doesn't work in onClick function
- React state is not updated after dispatch call using React useContext hook
- React Hooks jest testing - method is not a function
- React navigation with hooks and header function - state is not updating
- React Redux dispatch is not a function
- Passing a function as a callback to a React state created with hooks did not reflect new value of variable
More Query from same tag
- How can I do to see only day of the current month using a datepicker?
- How to add header to axios.create in react/redux app
- Does setState replace all existing data in a key, or just update what needs updating?
- Replace object in array on react state
- How can i manipulate DOM inside the onScroll event in ReactJS?
- [React]Module not found: You attempted to import ../../img/photo.jpg which falls outside of the project src/ directory. src/ are not supported
- CSS is ignoring background-image property
- How to avoid bind or inline arrow functions inside render method
- How to connect two APIs requests?
- How to save the rating to localstorage so it doesn't dissapear after refreshing?
- Argument of type 'unknown' is not assignable to parameter of type '{}'
- Show Json Value Consecutively with Material-UI Transition
- TypeError: Cannot destructure property 'cartItems' of 'cart' as it is undefined
- React JS animations based on JSON data
- Why is my fetch promise being stored in the prop as empty instead of the json i'm fetching?
- Render layout with N fixed columns in react JS
- In React, is it possible to skip re-render after setState if the state doesn't affect rendering?
- React Facebook Login popping up on page load
- How to use innerHTML for Accordion (PrimeReact)?
- React - hopefully simple formatting of a link
- Having problem in reset of checkboxes in react functional component want solution?
- How do I unit test Material-ui textfield using enzyme?
- TypeError: addProductPaymentResponse() missing 1 required positional argument: 'paymentForOrderID'
- Enzyme: How could I mock a function that passing as props
- Axios GET request to Spotify API returning 401
- Unable to get the object using typescript in reactjs
- How to remove arrow tooltip in react-bootstrap
- unhandledRejection: TypeError: Cannot destructure property 'protocol' of 'window.location' as it is undefined
- Get route parameters in React
- Image doesn't appear and whole page goes blank