G
G
grayordie2016-04-21 17:13:49
JavaScript
grayordie, 2016-04-21 17:13:49

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

3 answer(s)
M
Maxim, 2016-04-21
@maxfarseer

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
    }

and it's better to use payload rather than results. So "type" by standard convention.
Throw the whole project on github, and give a link in the comment.
ps if anything about redux in Russian here

G
grayordie, 2016-04-21
@grayordie

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.

P
psyhO_octopus, 2016-04-22
@psyhO_octopus

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 question

Ask a Question

731 491 924 answers to any question