I'm creating a simple React app with graphql, I'm using strapi as the server.
In Strapi I have a Vechicle collection type with a name field and a make field.
In the name field I have car and in make I have volvo, saab, audi, ford
I'd simple like to display car and the makes in a select menu.
The query to get the data
import gql from 'graphql-tag';
export const GET_ALL_CARS = gql `
query Cars{
cars{
_id
name
makes
}
}
`
The react page
import React from 'react';
import { GET_ALL_CARS } from './queries';
import {Vechicles} from './generated/Vechicles'
import { useQuery } from "@apollo/react-hooks";
const App:React.FC = () => {
const {data, loading} = useQuery<Vechicles>(GET_ALL_CARS, {})
if(loading) return <div>Loading</div>
if(!data) return <div>No Data</div>
return (
<div className="App">
<h1>Vehicles</h1>
{
data && data.vechicles && data.vechicles.map(vechicle => (
<div>
//car displays ok
{vechicle?.name}
//trying to create an array here from the string of makes
const makes_arr = {car?.makes ?? ''}.split(',')
<select>
{
makes_arr.map(make = > {
return(
<option>{make}</option>
)
})
}
</select>
</div>
))
}
</div>
);
}
export default App;
How do I simple display the comma seperated list in a select menu.
['volvo', 'saab', 'audi', 'ford']- Alexcarsorvechicles- choose one, matching your [real] query - xadm