react-redux-notify
react-redux-notify copied to clipboard
Loading notification state from localStorage fails
I regularly save my store to localStorage via JSON.stringify(). Upon page load, I load the localStorage store, and apply it to my store via a JSON.parse(). If notifications exist, the website fails to load.
The issue is with the icon, as it is a react node being saved as an object, and cannot be converted back to a node upon JSON.parse()
The error is:
Warning: Failed prop type: Invalid prop
iconsupplied to
Notification, expected a ReactNode.
Yea I can see why this could be a problem. I think best solution is to differentiate between being passed a string and element. If a string is passed as an icon we render an {(icon) ? <span className={styles.icon}><i className={icon}</span> : false />
else if its not then we render it as it currently is {(icon) ? <span className={styles.icon}>{icon}</span> : false}
.
I.E similar to this.
{(denyBtn.icon && typeof denyBtn.icon === 'string') ?
<i className={denyBtn.icon} />
:
denyBtn.icon
This way you can choose what works for your particular usecase. Would something like this suffice for you?