I have this JSON returned from the server:
[
{
"symbol":"one option"
},
{
"symbol":"second option"
}
.......
]
Service to get the data:
useEffect(() => {
const requestOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include',
};
fetch('/data', requestOptions)
.then((response) => {
if (response.status !== 200) {
throw new Error(response.status);
} else {
return response.json();
}
})
.then(
(futurePairs) => {
console.log(futurePairs)
props.onSetAvailableFuturesPairs(futurePairs);
},
(error) => {
console.log(error);
}
);
}, []);
......
onSetAvailableFuturesPairs: addAvailableFuturesPair,
......
export const ADD_AVAILABLE_FUTURES_PAIR = 'availableFuturesPairs:addAvailableFuturesPairs';
export function addAvailableFuturesPair(newPair) {
return {
type: ADD_AVAILABLE_FUTURES_PAIR,
payload: {
newPair: newPair
}
}
}
......
availableFuturesPairs: [],
......
Display data:
<Select
onChange={event => changeSelectedFuturesPair(event.target.value)}
value={props.selectedFuturesPair}>
{props.availableFuturesPairs.map((option) => (
<option key={option.symbol} value={option.symbol}>{option.symbol}</option>
))}
</Select>
But I get error:
`Warning: Each child in a list should have a unique "key" prop.`
Do you know how I can fix this?