ui-router / redux

UI-Router plugin for Redux integration
MIT License
12 stars 6 forks source link

Is not working with react-redux 6 #9

Closed rcanessa89 closed 4 years ago

rcanessa89 commented 5 years ago

Is not working with react redux 6.0.1, the problem is the store value in the context, is coming undefined, looks like the current version of "ui-router/redux" is using the legacy React context API.

I builded this solution for my project but the context API should be change it for future versions of React.

import store from '@store';
import { pushStateLocationPlugin, UIView } from '@uirouter/react';
import { ConnectedUIRouter } from '@uirouter/redux/lib/react';
import * as PropTypes from 'prop-types';
import * as React from 'react';
import config from './config';
import { router } from './index';
import states from './states';

const plugins = [
  pushStateLocationPlugin
];

export default class AppRouter extends React.Component<any> {
  public static childContextTypes = {
    store: PropTypes.object
  };

  public getChildContext() {
    return {
      store,
    };
  }

  public render() {
    return (
      <ConnectedUIRouter
        router={router}
        plugins={plugins}
        states={states}
        config={config}
      >
        <UIView />
      </ConnectedUIRouter>
    );
  }
}
DamianOsipiuk commented 5 years ago

@elboman +1 for this. Two solutions:

  1. Move to the new context API (breaking change requiring version bump, not ideal)
  2. Give possibility to provide store as a prop. (this solution is actually backwards compatible).

Currently have to patch it up locally. https://react-redux.js.org/using-react-redux/accessing-store

elboman commented 5 years ago

Hey, thanks for filing the issue.

I think it's fair to go with solution number one, as the current version is 0.1.x and we were expecting breaking changes anyway.

React hooks are here to stay, and I assume, given the super simple upgrade path for react-redux, most users will be using the latest version anyway.

I'm about to push an update that converts ConnectedUIRouter to a function component with hooks, and that supports the newer version of Redux.

elboman commented 5 years ago

Hey, I've put up #10 to tackle this, what do you think?

marcellino-ornelas commented 5 years ago

@elboman any updates on this? Having the same issue

DamianOsipiuk commented 4 years ago

@elboman Can you say when this could be released? It would be nice to have the original package instead of a forked one.

christopherthielen commented 4 years ago

https://github.com/ui-router/redux/releases/tag/1.0.0

I don't actually use this project, but I released @elboman 's PR as 1.0.0. let me know if this works for ya'll or not.