-
Notifications
You must be signed in to change notification settings - Fork 15
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
Get rid of deprecated componentWillReceiveProps #38
Comments
From @soda0289 in #35 (comment) :
|
@soda0289 I believe your suggestion of updating the polyglot instance in the render-method should work well for I'm not so sure about the messages though: When calling At a first glance I would assume that what we want is the What do you think? |
I think memoizing the input props is the correct solution. If we use the new react hooks they offer useMemo() which would work well in this siutaion but we would have to convert the component class into a component function to use hooks. function I18n({children, locale, messages}) {
const translate = React.useMemo(() => {
this._polyglot.locale(this.props.locale)
this._polyglot.replace(this.props.messages)
return this._polyglot.t.bind(this._polyglot)
}, [locale, messages]);
return (
<I18nContext.Provider value={translate}>
{React.Children.only(children)}
</I18nContext.Provider>
)
}
} If we used memoize-one would it just be something like: function render() {
const getTranslate = memoizeOne(
(locale, messages) => {
this._polyglot.locale(this.props.locale)
this._polyglot.replace(this.props.messages)
return this._polyglot.t.bind(this._polyglot)
}
);
const translate = getTranslate(locale, messages);
return (
<I18nContext.Provider value={translate}>
{React.Children.only(children)}
</I18nContext.Provider>
);
} Would it be ok to do a shallow comparsion of messages object. For my use case I always load the messages from a json file so the object never changes. Which would allow for shallow or "===" comparison. |
I believe we should do a shallow comparison only (and probably document this). Anything else could result in serious performance problems. |
@ctavan @nayaabkhan Any preference between using the react hooks with function component or should we be using the class component and bring in the memozineOne dependency? |
I‘m personally a big fan of hooks and would favor it. We just need to make sure to adjust the react peerDependency accordingly and release the new version of this library as 0.7.0 |
Speaking of hooks: It would then of course also be nice to have a |
Whoops, of course! Sorry for missing out on that one! |
I think it would be fine to move our React |
Cool! @soda0289 are you planning to make a pull request? Just so we don’t work both on it at the same time. |
@ctavan Yes I can work on this today or tommrow. |
Hi! Any updates on this issue? |
@puredazzle Hi! I will check the PR #39 that resolves this issue in the coming days. |
Released |
componentWillReceiveProps
is deprecated and will be removed in React 17.It's currently being used to update the internal node-polyglot instance when the
<I18n>
component's props change:react-polyglot/src/i18n.js
Lines 22 to 30 in db80a63
We need to find a future-proof way of updating the internal node-polyglot instance.
The text was updated successfully, but these errors were encountered: