Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
react redux importing reducer dispatch

I'm trying to follow the counter example in the react-redux template, but I can't seem to export my own setOwner reducer.

ownerSelector.tsx:

export  const ownerSlice = createSlice({
  name: 'owner',
  initialState,

  reducers:{
    setOwner: (state) => {    //Export this reducer
      let own = document.getElementById("OwnerSelector") as HTMLSelectElement
      state.id = parseInt(own!!.options[own.selectedIndex].value);
    }
  },
  extraReducers: (builder) => {}
})

export const selectOwner= (state: RootState) => state.selectedOwner.id;
export default ownerSlice.reducer;

where I want to import setOwner in carForm.tsx:

import {setOwner} from './ownerSelector'; // error here


    let submitHandler = (e: React.FormEvent<HTMLElement>) => {
        e.preventDefault();

        dispatch(setOwner())
        const formData = {
            car: {
                year: year,
                make: make,
                model: model,
                price: price,
                person_id: owner,
            }
        }
        dispatch(createCarAsync(formData));
        resetState();
    }

The error at the import is: Module '"./ownerSelector"' has no exported member 'setOwner'. Did you mean to use 'import setOwner from "./ownerSelector"' instead?ts(2614)

What am I doing wrong? Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In redux toolkit and in any redux you need to dispatch actions.

export const { setOwner } = ownerSlice .actions 
//now you can use it in dispatch 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!