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

217
Views
react native redux : actions.(~~~~) not defined how to use dispatch and import actions?

part of App.js

import { createStore } from 'redux';
import { Provider,useDispatch,useSelector } from 'react-redux';
import reducers from './reducers';
import * as actions from './actions';
const store = createStore(reducers);

const App = () => {
  return(
    <Provider store={store}>
        <MyComponent>
    </Provider>
  );
};

//----------------------

part of my component

const dispatch = useDispatch()

dispatch(actions.addPost(text));

//------------------

actions - index.js
export const addPost = (text) => ({
   type : 'ADD',
   text
});

//----------------- reducers - index.js

const initialState = {
   posts : [],
};

const posts = (state=initialState,action) => {
const {posts}= state;
switch(action.type){
   case 'ADD':
       return({
           posts: [
               {
               idx : Math.random(),
               userIdx: 'user123',
               text: actions.text
               },
               ...posts,
           ]
       });
};
};

export default posts;

//------------------------------

i declare addPost in index.js in actions folder and export it but when i use it, error has been occurred and it said "TypeError: actions.addPost is not a function. (In 'actions.addPost(text)', 'actions.addPost' is undefined)"

Why my components can't recognize actions? Is there anything i should add? this is my project folder structure. enter image description here

about 4 years ago · Santiago Trujillo
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!