It is a terrible idea, but probably the best/easiest way to use a global variable in React is to put it on the window
. In a component you could do something like window.topicText="some text"
and then access it via window.topicText
everywhere else.
Ideally, if you have data, and in your case likely state, that you need to persist from component to component, you should look into something like Redux or Flux. I prefer Redux.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…