Answer the question
In order to leave comments, you need to log in
How to replace a component when the window changes?
Goodnight. Can you please tell me how can I return the corresponding component when the window changes?
export default function TopBar() {
return (
<Router>
<GetNavigationAndLogo />
</Router>
)
}
export const GetNavigationAndLogo = () => SelectNavigation(navigationItems);
const SelectNavigation = (menuItems) => {
document.addEventListener('resize', () => {
return window.innerWidth < 1000 && window.innerWidth > 700 ?
getNavigationTablet(menuItems) :
window.innerWidth < 700 ? getNavigationMobile(menuItems) :
getNavigationPC(menuItems);
});
window.innerWidth < 1000 && window.innerWidth > 700 ?
getNavigationTablet(menuItems) :
window.innerWidth < 700 ? getNavigationMobile(menuItems) :
getNavigationPC(menuItems);
};
Answer the question
In order to leave comments, you need to log in
You can update the application during resizing with this not tricky design:
window.onresize = () => {
ReactDOM.render(<App />, document.getElementById('root'));
};
Everything is simple. Add a state to SelectNavigation and store the flag of the desired type there:
state: {
view: 'pc'; //pc | tablet | 'mobile'
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question