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

PrevProps the same as current props #508

Closed
lomboboo opened this issue Sep 5, 2018 · 5 comments
Closed

PrevProps the same as current props #508

lomboboo opened this issue Sep 5, 2018 · 5 comments

Comments

@lomboboo
Copy link
Contributor

@lomboboo lomboboo commented Sep 5, 2018

Hi and thanks for awesome library.

I use react-i18next in my project and I've got an issue when I want to access prevProps within ComponentDidUpdate for example. In this case language field in the i18n object is the same as this.props. You can see it in this demo .

I took a look in the core and found that inside translate HOC you mutate i18n object.

Is there any reason why it was implemented this way? I'd really like to have prevProps has correct values

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Sep 5, 2018

it is the same object (singleton) and not an immutable...it just try to look it up in the different possible locations (context, props, ...)

what exactly is your issue - why you need that previous language?

@lomboboo

This comment has been minimized.

Copy link
Contributor Author

@lomboboo lomboboo commented Sep 5, 2018

Thanks for quick response.

I have a case where I need to do some async calls when language changed. So I'd have condition in the ComponentDidMount something like this.props.i18n.language !== prevProps.i18n.language then do some logic.

Although i18next has languageChanged event, it's inconvenient to use in the react app. It'd be much simpler if prevProps worked "react like".

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Sep 5, 2018

hm...then i would suggest we pass lng from translate to component as a prop...the i18n instance is based on i18next and can't be really changed therefor

so adding it to the I18n render props which is used in translate hoc and from there add it to components props?!?

@lomboboo

This comment has been minimized.

Copy link
Contributor Author

@lomboboo lomboboo commented Sep 5, 2018

I can work on PR, but I'm not sure what are you referring to. You're talking about pass as prop here?

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Sep 5, 2018

yes and also here: https://github.com/i18next/react-i18next/blob/master/src/I18n.js#L124

basically passing it from that I18n to the line you showed above...

feel free to make a PR

jamuhl added a commit that referenced this issue Sep 10, 2018
related to issue #508: react_i18n object property
@jamuhl jamuhl closed this Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.