react-redux-notify icon indicating copy to clipboard operation
react-redux-notify copied to clipboard

Loading notification state from localStorage fails

Open ZephD opened this issue 8 years ago • 1 comments

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 toNotification, expected a ReactNode.

ZephD avatar Oct 27 '16 12:10 ZephD

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?

deep-c avatar Oct 28 '16 02:10 deep-c