Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support React-Redux v6. #176

Closed
wgao19 opened this issue Nov 7, 2018 · 14 comments · Fixed by #191
Closed

Support React-Redux v6. #176

wgao19 opened this issue Nov 7, 2018 · 14 comments · Fixed by #191

Comments

@wgao19
Copy link
Contributor

wgao19 commented Nov 7, 2018

React-Redux v6 will use React's ( new ) context api which is not compatible with the legacy context API. By accessing store from context ( reference ) it causes the app to break when it tries to dispatch the LOCATION_CHANGE action.

As @timdoor has described in its breaking changes:

Passing store as a prop to a connected component is no longer supported. Instead, you may pass a custom context={MyContext} prop to both <Provider> and <ConnectedComponent>. You may also pass {context : MyContext} as an option to connect.

Related React-Redux links:

@BiosBoy
Copy link

BiosBoy commented Nov 16, 2018

Same issue here! There is a problem with how to bring react-redux 6*.beta and connected-react-router 5* work together. I gets an error about missing context store object in ConnectedRouter each time when trying to start my project...

@Jessidhia
Copy link

That'll require a breaking change / major version. connected-react-router needs to look into react-redu x's context but it's been moved from old context to new context.

@wgao19
Copy link
Contributor Author

wgao19 commented Nov 20, 2018

Pulling up a fix for my own usage that here may refer to

@supasate
Copy link
Owner

supasate commented Nov 25, 2018

Based on @wgao19's fix, I made a PoC in #191. Please check it out and let me know what you all think.

Update: I just published it as connected-react-router@next (v6.0.0-beta.1).

@bugzpodder
Copy link

Thanks for the awesome work!
react-redux just released the final version of v6: https://github.com/reduxjs/react-redux/releases/tag/v6.0.0
Gonna give the connected-react-router@next branch a try later to see how it works out together!

@kaigouthro
Copy link

thows hands up... damnit!... i just got the notice from greenskeeper on the boilerplate i grabbed and cleaned up. it's too big to go through and update to redux 6, and i just spent 40 hours on a new boilerplate centered on connected-react-router and redux 5. there goes all that work.

any viable redux 6 ready alternatives, someone let me know, please.

@ahce
Copy link

ahce commented Dec 5, 2018

connected-react-router 6.0.0-beta.1 works for me with react-redux 6.0.0

@kaigouthro
Copy link

kaigouthro commented Dec 5, 2018 via email

@Ariex
Copy link

Ariex commented Dec 6, 2018

this problem been bug me for a while, finally find the solution, thanks!

@samuelpena
Copy link

Worked for me as well! Thanks!

@johnryan
Copy link

johnryan commented Dec 6, 2018

I tried setting this up with 6.0.0-beta1 like so:


const routerContext = React.createContext(null);
export default class Root extends React.Component<RootType, {}> {

  render() {
    return (
      <Provider store={this.props.store} context={routerContext}>
        <div>
          <GlobalStyle />
          <ConnectedRouter history={this.props.history} context={routerContext}>
            <App />
          </ConnectedRouter>
        </div>
      </Provider>
    );
  }
}

but still seeing the error:
Uncaught Error: Could not find "store" in the context of "Connect(App)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(App) in connect options.

Is there another step that's missing here other than passing the context to ConnectedRouter?

@bugzpodder
Copy link

I upgraded to react-redux v6 and connected-react-router v6 and everything worked.

@kaigouthro
Copy link

i've got this >

 
import React from 'react';
import ReactDOM from 'react-dom';
import { combineReducers } from 'redux';
import { createBrowserHistory } from 'history';
import { AppContainer } from 'react-hot-loader';
import { PersistGate } from 'redux-persist/integration/react';
import { fbContext } from '@root/actions/Firebase/fbContext';
import configureStore from '@root/store/configureStore';
import { BrowserHistory } from 'connected-react-router';
import { Firebase } from '@root/actions/Firebase';
import { ReduxConfig } from '@root/controllers/store/createStore';
import rootReducer from '@root/controllers/reducers/reducersducers';
import * as serviceWorker from './serviceWorker';
import App from '@root/App';

const { initialState } = configureStore(ReduxConfig);
const { persistor } = configureStore(BrowserHistory);
const store = combineReducers(rootReducer, persistor, initialState);
const history = createBrowserHistory();

const render = () => {
  ReactDOM.render(
    <AppContainer>
      <PersistGate loading={null} store={store} persistor={persistor}>
        <fbContext.Provider store={store} firestore={new Firebase()}>
          <App store={store} routes={routes} />
        </fbContext.Provider>
      </PersistGate>
    </AppContainer>,
    document.getElementById('react-root')
  );
};


  //  serviceWorker.register();

wrapped around this >>>


import React from 'react'
import ReactDOM from 'react-dom'
import { AppContainer } from 'react-hot-loader'
import { Provider, render } from 'react-redux'
import Appz from './Appz'

import { store, history } from '../index'

export default class App {
  render = ({ store, history } = ((
    <AppContainer history={history} store={store}>
      <Appz />
    </AppContainer>
  ),
  document.getElementById('react-root')))
}

wrapped around this..


/* eslint-disable no-unused-vars */
import { Container, Divider, Message, Segment } from 'semantic-ui-react'
import PropTypes from 'prop-types'
import React from 'react'
import { renderRoutes } from 'react-router-config'
// import Helmet from 'react-helmet';
// import '../styles/semantic.less';
// Import { Notifs } from '@root/assets/modules';
// import '../styles/heading.less'
import { ConnectedRouter, Route, Switch } from 'connected-react-router'
import mainNav from '../controllers/mainNav'


export const Appz = ({ routes, store, history }) => (
  <ConnectedRouter history={history}>
    <div>
      <mainNav>
        <Switch>
          <Route exact path="/" render={() => <div>Match</div>} />
          <Route render={() => <div>Miss</div>} />
        </Switch>
      </mainNav>
    </div>
  </ConnectedRouter>
)

Appz.propTypes = {
  history: PropTypes.element.isRequired,
  routes: PropTypes.element.isRequired,
  store: PropTypes.element.isRequired
}

export default Appz

wroking.

ihave a couple things turned off, in super dev mode right now... took 6 different starters and boilerplates and mashed them together with 10 different tutorials.. it's getting pretty savage... when done, it'll be the scaffolding for super-projects.... like... really really ambitious builds.. code splitting, SSR, loadable components and hot reducer reloading, tons of dev tools, local and cloud noSQL, socket.io api client..

thios router is just right and tight and appears to work with nesting.. going to be important when i set up sub routers...

but yes... it Works.

@supasate
Copy link
Owner

supasate commented Dec 9, 2018

Connected React Router v6.0.0 has been released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants