React Redux Router Error

I am trying to configure a Redux + React Router app. I think the problem is with ImmutableJS, but I don’t understand how to solve it.

client.js

import { fromJS } from 'immutable'
import React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import { AppContainer } from 'react-hot-loader'

import { Provider } from 'react-redux'
import { match, Router, browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'

import { createStore, combineReducers, compose, applyMiddleware } from 'redux'
import { routerReducer, routerMiddleware } from 'react-router-redux'

function createSelectLocationState(reducerName) {
  let prevRoutingState;
  let prevRoutingStateJS;

  return (state) => {
    const routingState = state.get(reducerName); // or state.routing

    if (!routingState.equals(prevRoutingState)) {
      prevRoutingState = routingState;
      prevRoutingStateJS = routingState.toJS();
    }

    return prevRoutingStateJS;
  };
}

function configureStore(history, initialState) {
  const reducer = combineReducers({
    routing: routerReducer
  });

  return createStore(
    reducer,
    initialState,
    compose(
      applyMiddleware(
        routerMiddleware(history)
      )
    )
  );
}

const initialState = fromJS(window.__INITIAL_STATE__);
const store = configureStore(browserHistory, initialState);
const history = syncHistoryWithStore(browserHistory, store, {
  selectLocationState: createSelectLocationState('routing')
});
const rootNode = document.getElementById('root');

const renderApp = () => {
  const routes = require('./routes');

  match({ history, routes }, (error, redirectLocation, renderProps) => {
    render(
      <AppContainer>
        <Provider store={store}>
          <Router {...renderProps} />
        </Provider>
      </AppContainer>,
      rootNode
    );
  });
};

// Enable hot reload by react-hot-loader
if (module.hot) {
  const reRenderApp = () => {
    try {
      renderApp();
    } catch (error) {
      const RedBox = require('redbox-react').default;

      render(<RedBox error={error} />, rootNode);
    }
  };

  module.hot.accept('./routes', () => {
    setImmediate(() => {
      // Preventing the hot reloading error from react-router
      unmountComponentAtNode(rootNode);
      reRenderApp();
    });
  });
}

renderApp();

I get this error:

Uncaught TypeError: state.get is not a function

enter image description here

To statethis object

enter image description here

I'm using "react": "^15.3.2", "redux": "^3.6.0","react-router": "^3.0.0"

UPDATE 1 Now I use combineReducersfrom redux-immutable:

import {combineReducers} from 'redux-immutable'

But get the error:

Uncaught TypeError: routingState.equals is not a function

enter image description here

Here:

enter image description here

UPDATE 2

I fixed this problem, but there is another error

enter image description here

All code sent to this repository

+4
source share
2 answers

src/index.js require route.js.

require es6 , default, require d. - ,

const routes = require('./routes').default;

- git.

+1

combineReducers immutable. immutable, fromJS(blah), . redux-immutable:

import {combineReducers} from 'redux-immutable';

0

Source: https://habr.com/ru/post/1662378/


All Articles