The meaning of life is to explore the world

some ways to share data among React components

Posted on By Jason Liu

some ways to share data among React components
1.static data of a class

2.export const

export const data = Object.freeze({
	key1: 'value1',
	key2: 'value2'
})

3.Context
Note:

  • useContext() can only apply to functional component
  • It’s usually recommended to use MyContext.Consumer inside render() method but not outside