如何在react admin中动态更改http头?

如何在react admin中动态更改http头?,http,http-headers,react-admin,api-platform.com,Http,Http Headers,React Admin,Api Platform.com,不重要,但是:我使用react admin w/Symfony(Api平台)后端。文件是。身份验证文档为 是的,我知道,我可以像这样向数据提供程序添加自定义头 let locale = 'en_GB'; const entrypoint = document.getElementById('api-entrypoint').innerText; const fetchHydra = (url, options = {}) => baseFetchHydra(url, { ...

不重要,但是:我使用react admin w/Symfony(Api平台)后端。文件是。身份验证文档为

是的,我知道,我可以像这样向数据提供程序添加自定义头

let locale = 'en_GB';

const entrypoint = document.getElementById('api-entrypoint').innerText;

const fetchHydra = (url, options = {}) => baseFetchHydra(url, {
    ...options,
    headers: new Headers({
        Authorization: `Bearer ${window.localStorage.getItem('auth')}`,
        'X-LOCALE': locale, // <----- THIS IS THE POINT - I WOULD LIKE
                                      TO CHANGE THIS HEADER LATER, W/O RELOAD THE PAGE
    }),
});

const apiDocumentationParser = entrypoint => ....more code

const dataProvider = baseHydraDataProvider(entrypoint, fetchHydra, apiDocumentationParser);

ReactDOM.render(
    <HydraAdmin
        dataProvider={dataProvider}
        ....more code>
        ....more code
    </HydraAdmin>,
    document.getElementById('api-platform-admin')
);

我在appBar中创建了一个选择字段:

...more code

    const handleChangeLocale = (event) => {
        localStorage.setItem('locale', event.target.value);
        window.location.reload();
    };

    return (
        <AppBar {...props} className={classes.appbar}>
            ...more code
            
            <Select
                value={localStorage.getItem('locale')}
                onChange={handleChangeLocale}>
                <MenuItem value={"en_US"}>English, US</MenuItem>
                <MenuItem value={"en_GB"}>English, GB</MenuItem>
            </Select>
        </AppBar>
    );
…更多代码
常量handleChangeLocale=(事件)=>{
localStorage.setItem('locale',event.target.value);
window.location.reload();
};
返回(
…更多代码
英语,美国
英语,GB
);
我发现这是一个丑陋的解决方案。但我找不到与官方文件相关的更好的解决方案。很明显,我试过和我最好的朋友一起玩:谷歌,Qwant,Duckduckgo

...more code

    const handleChangeLocale = (event) => {
        localStorage.setItem('locale', event.target.value);
        window.location.reload();
    };

    return (
        <AppBar {...props} className={classes.appbar}>
            ...more code
            
            <Select
                value={localStorage.getItem('locale')}
                onChange={handleChangeLocale}>
                <MenuItem value={"en_US"}>English, US</MenuItem>
                <MenuItem value={"en_GB"}>English, GB</MenuItem>
            </Select>
        </AppBar>
    );