EugeneMeles / laravel-react-i18n

Allows to connect your `Laravel` Framework translation files with `React`.
MIT License
73 stars 8 forks source link

State got lost on language change #3

Closed parth391 closed 2 years ago

parth391 commented 2 years ago

https://user-images.githubusercontent.com/4966579/200322270-cb6de8ee-390c-4e86-ae63-c0117afc44c6.mov

My app.ts file

import { LaravelReactI18nProvider } from 'laravel-react-i18n';

createInertiaApp({
    ...
    setup({ el, App, props }) {
        const root = createRoot(el);
        root.render(
            <Provider store={store}>
                <LaravelReactI18nProvider
                    lang={'en'}
                    fallbackLang={'en'}
                    resolve={async (lang) => {
                        const langs = import.meta.glob('/lang/*.json');
                        try {
                            return await langs[`/lang/${lang}.json`]();
                        } catch (e) {
                            //
                        }
                    }}>
                    <App {...props} />
                </LaravelReactI18nProvider>
            </Provider>

        );
    },
});

To set lang

setLang(lang);
EugeneMeles commented 2 years ago

Hi @parth391 ! Please clarify, does your component Provider use React.Context store?

This may be because authorization is being re-rendered and store reset to default. It may be necessary to take its(auth store) outside of LaravelReactI18nProvider provider

parth391 commented 2 years ago

@EugeneMeles, I removed the store and auth process, but its doing the same behaviour.

I have created a sample repository. On login page you can find the change lang button. On clicking, its redirecting me to the home page.

parth391 commented 2 years ago

@EugeneMeles,

https://user-images.githubusercontent.com/4966579/200644748-cd484d2e-47dc-4ff5-b5e8-94b93b90fb73.mov