Questions tagged [react-reducer]

10 questions
5
votes
1 answer

How to use React.useReducer (or equivalent) in class component?

Is there any way to use useReducer or any equivalent thing in React native class Components? Yeah reducer method is raw js function. Can we use it in class directly rather joining it with states of class? function init(initialCount) { return…
CrackerKSR
  • 1,380
  • 1
  • 11
  • 29
1
vote
1 answer

REDUX concept queries: 2 ways OR 3 ways to access a redux store. Why use thunk and missing createStore parameters

I am learning about react + redux. I have 3 questions related to it. query-1: The ways to access a store inside a component. According to the official documentation here there are 2 ways hooks(useSelector etc.) connect. By importing store in our…
octanium
  • 23
  • 4
1
vote
1 answer

Why the event handler function cannot get the updated state object value?

Here is my code: App.js: import './App.css'; import { useAlarmClock } from "./useAlarmClock"; export default function App() { const[action,data]=useAlarmClock(); let start=()=>{ action.start(); } return (
The KNVB
  • 3,588
  • 3
  • 29
  • 54
0
votes
1 answer

How to handle events through parent children components in React without external libraries?

I try to find solution how to handle events in React parent<->children components without external libraries. Example, let's imagine we build Select (dropdown) component. Inside one parent component there are children components like leftIcon,…
0
votes
1 answer

Migrate React Context to Redux

I was using a free React template which was implemented with Context+Reducer and soon, after adding complexity, I ran accross the classic re-render caveat of useContext API. Is it possible to change my Context interface to one of Redux, since I…
0
votes
1 answer

React Reducer State Correctly Set But Function in Context Doesn't Reflect It

I have a problem around React (Next) Context/Reducer. I've already written components with Context and Reducer and don't understand why it's not working as excpected. The problem is that the reducer's state is set and logged correctly in useEffect…
sntrcode
  • 202
  • 1
  • 7
  • 10
0
votes
0 answers

Failing at optimizing context value

I'm following this pattern to try to optimize the component tree rendering however I need the initial state to be passed via props to my provider that looks like this: const EditorProvider = ({ children, initialState, }: { children:…
0
votes
0 answers

React reducer updating array of textboxes

I have a state with a object array. This object array is looped to render number of textboxes in the page. When I type in a textbox (after one key press), focus is removed from the textbox. Then I need to click on the textbox again to type.. I…
Kasun
  • 196
  • 1
  • 14
0
votes
0 answers

Use custom middleware for async actions - Uncaught Error: Actions must be plain objects

I am getting following error on redux store for async calls, I read few of the stack-overflow solutions but it doesn't help much : Error: Uncaught Error: Actions must be plain objects. Use custom middleware for async actions. at dispatch…
0
votes
0 answers

React Context; useReducer Pattern: Can/Should properties on initialState have functions to update initialState?

I have a custom hook which I am trying to move into the context/reducer pattern: import { sortDateStrings } from '@/Utils/SortDateStrings' function useDiscounts ({ data }) { const [effectiveDates] = useState(data.effectiveDates || []) …