'Use imports with string that comes from localStorage
I need to show/hide different menu based on rights that are send from database and saved in localStorage.
Here is the imported menus
import tripOrders from './tripOrders';
import orders from './orders';
import employees from './employees';
Then I use them here:
const menuItems = {
items: [tripOrders, orders, employees]
};
I tried to make something like this, but nothing happens.
let menuFromDB = localStorage.getItem('menu-items') // <== in 'menu-items' I set tripOrders, orders, employees
const menuItems = {
items: [menuFromDB]
};
Solution 1:[1]
You get a string from localStorage, so you can use split()
to convert it to the array
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sasa |