Answer the question
In order to leave comments, you need to log in
What is the problem with reducer in redux?
Guys, why after the action I don't get to the reducer?
I am attaching the code
import * as types from '../constants/ActionTypes'
const initialState = {
name: null,
surname: null,
email: null,
password: null,
isEmailRepeat: false,
isPasswordRepeat: false,
company: null,
city: null,
employeeName: null,
employeeProfession: null,
employers: []
};
export default function sampleReducer(state = initialState, action) {
switch (action.type) {
case types.CHANGE_FIELD:
console.log(1);
return {
...state,
[action.result.field]: action.result.data
}
// case types.NEXT_STEP:
// case types.PREVIOUS_STEP:
// case types.ADD_EMPLOYEE:
// case types.REMOVE_EMPLOYEE:
default:
return state;
}
}
import * as types from '../constants/ActionTypes';
export function changeField(field, data) {
console.log(field, data);
return {
type: types.CHANGE_FIELD,
resuls: {
field,
data
}
};
}
import React, { Component } from 'react';
import { combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { createStore, renderDevTools } from '../store_enhancers/devTools';
import SampleApp from './SampleApp';
import * as reducers from '../reducers';
const reducer = combineReducers(reducers);
const store = createStore(reducer);
export default class App extends Component {
render() {
return (
<div>
<Provider store={store}>
{() => <SampleApp /> }
</Provider>
{renderDevTools(store)}
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Console log does not even pop up?
I don’t really want to delve into it at night, I’ll just say by the code - a typo in
resuls: {
field,
data
}
Yes, and redux, in general, I know, I just don’t understand in principle what’s the matter here. I can't post the project yet, sorry.
Little code. It is not visible how you call the action, how you connected the reducer to the store is also not visible. Perhaps the problem is there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question