Search code examples
reactjsdrycomposition

I have a configuration JSON I want to share between React components, what's the best way?


I'm going to be using some configuration data that I want shared between several different React components. Instead of coding those config data objects into each component I want to be able to DRY it up into one file/json string and share that object between components.

What's the most sane/best way of doing this?

(I was looking at Mixins and noticed that they're being deprecated in React at some point, so wanted to avoid this. https://facebook.github.io/react/blog/2015/03/10/react-v0.13.html )

What are other possibilities? Passing an obj into via properties? Creating a file and importing it? Other better ways?


Solution

  • You can keep it in state and pass those configuration as default props to every component.