Szilard Magyar Szilard Magyar - 5 months ago 21
YAML Question

how to use static data in react

I have a select tag with over 40 options, so my component looks pretty lame. I'd rather create a static data file and iterate over the data, but I'm new to react and don't know what the proper way to solve this issue. Any ideas? Is YAML a good idea for react apps?

render() {
return (
<h4>Choose an arrival train station</h4>
<select className='form-control'
onChange={event => this.onInputChange(}>
<option value="12th">12th St. Oakland City Center</option>
<option value="16th">16th St. Mission (SF)</option>
<option value="19th">19th St. Oakland</option>
<option value="24th">24th St. Mission (SF)</option>
<option value="ashb">Ashby (Berkeley)</option>
<option value="balb">Balboa Park (SF)</option>
<option value="bayf">Bay Fair (San Leandro)</option>
<option value="cast">Castro Valley</option>
<option value="civc">Civic Center (SF)</option>
<option value="cols">Coliseum</option>
<option value="colm">Colma</option>


You should just use js; including yaml for something that's probably going to be used on the web and so needs to be js anyways just complicates your build process. Making the options would look roughly like this:

const staticData = [
    { value: "...", label: "..." },
    // ...

{ => <option value={o.value}>{o.label}</option>) }