Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda