ratson / react-intl-redux

Redux binding for React Intl.
MIT License
298 stars 48 forks source link

Option to provide keySelector to #6 workaround #36

Closed smokku closed 6 years ago

smokku commented 7 years ago

Unfortunately #6 workaround does not help with the case when only messages change (i.e. after downloading new version from server), but locale stays the same.

This change introduces an option to provide own selector setting the key. There isn't one-size-fits-all solution, as every project has own messages structure, so it cannot be fixed for all.

In my case the solution is as simple as:

const keySelector = (intl) => `${intl.locale}-${JSON.stringify(intl).length}`

...
      <Provider store={store}>
        <IntlProvider keySelector={keySelector}>
ratson commented 7 years ago

@smokku Thanks for your PR. Would you send another PR with a test case describing the problem, so I could try different approach? I am wondering if there is a better solution for this.

ratson commented 6 years ago

intlSelector with key property should do the same.