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

/!\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.useWrappedStore(). #488

Closed
ribeaud opened this issue Sep 13, 2022 · 8 comments
Labels

Comments

@ribeaud
Copy link

ribeaud commented Sep 13, 2022

Describe the bug

Since v8.0.0, I am getting following warning in the console:

/!\ You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.useWrappedStore().

This is NOT the case with 7.0.5.

Because I was not able to find any release notes for next-redux-wrapper, I am not sure whether the problem is on my side, or on next-redux-wrapper's side.

Expected behaviour

The warning does NOT appear.

Desktop (please complete the following information):

  • OS: macOS Monterey v12.6
  • Browser: Chrome v105.0.5195.102
@ribeaud ribeaud added the bug label Sep 13, 2022
@aldabil21
Copy link

You did not provide code snippet of your _app
So I assume that it's like:

// ...
// Your _app
// ... 

export default wrapper.withRedux(MyApp);

Instead, replace it with:

const MyApp = ({ Component, ...rest }: AppProps) => {
  const { store, props } = wrapper.useWrappedStore(rest);
  return (
    <Provider store={store}>
      <Component {...props.pageProps} />
    </Provider>
  );
};

export default MyApp;

source: redux toolkit example

@kirill-konshin
Copy link
Owner

@ribeaud this behavior is by design. @aldabil21 is absolutely correct, it is the recommended way to use the library.

@ribeaud
Copy link
Author

ribeaud commented Sep 15, 2022

Thank you guys. And sorry to be so lazy...

Unfortunately, I am still a bit lost (NOT being an expert here). Our _app code is located here.

How should I update this code?

@kirill-konshin
Copy link
Owner

@phryneas
Copy link

phryneas commented Sep 18, 2022

I came here because someone had a StackOverflow question on this - and checking the repo, this is acutally not really mentioned in the README at the moment.

There is a section on useWrappedStore but ironically it shows the wrapper.withRedux HOC - that one might need an update :)

@ribeaud
Copy link
Author

ribeaud commented Sep 21, 2022

For who is interested (could not find a better way...), I ended up with following solution (using this app definition):

const AppWrapper = ({ Component, ...rest }: AppProps): ReactElement => {
  const { store, props } = wrapper.useWrappedStore(rest);
  return (
    <Provider store={store}>
      <App Component={Component} {...props} />
    </Provider>
  );
};

export default appWithTranslation(AppWrapper, nextI18NextConfig);

@kirill-konshin
Copy link
Owner

The section in readme has been corrupted somehow after merges, I've fixed it: https://github.com/kirill-konshin/next-redux-wrapper#wrapperusewrappedstore

@nnurmano
Copy link

The section in readme has been corrupted somehow after merges, I've fixed it: https://github.com/kirill-konshin/next-redux-wrapper#wrapperusewrappedstore

It still shows wrapper.withRedux code with a class component, could you please update the code?

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

No branches or pull requests

5 participants