This seems like quite a silly question but to this point I haven't been able to find a clear answer.
I'm looking for essentially a best practice to storing variables and helper functions in JavaScript. I need to keep this list updated locally, so my first instinct is to store it outside the react class globally, but clearly this is a bad idea as I will eventually need to add helper functions and more variables to be used in my component.
import React, { Component } from 'react';
import Select from 'react-select';
const list = ['1', '2', '3'] // is it acceptable to store this here?
export class Example extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<div className="well">
<div className="row">
<div className="col-sm-4">
<h3>Device Type</h3>
<Select options={list}/>
</div>
</div>
</div>
)
}
}
I've read about many different design patterns (module, singleton, revealing, etc...) in Javascript to avoid polluting the global namespace, but I'm not sure what my best option is.
So again, my question is, what's the best practice for storing variables and helper functions that need to be used by my react component/class without just throwing everything into the global namespace.
EDIT
Obviously this is a very broad question and I'm assuming I'll receive some grief for asking it. If there's a better way to ask it please let me know. A link to some other resource that answers the question would also be very helpful.
Someone in the comments mentioned that using ES6 modules already handles the global pollution problems that existed in Javascript before. Is it ultimately okay for me to store helper functions and variables outside my class without any repercussions?