how to render select children options after receiving option array from api #3107
Unanswered
akshayp660
asked this question in
Q&A
Replies: 1 comment
-
@akshayp660 you can use React State for this, like: const MyOptionsField = (props) => {
const [options, setOptions] = React.useState([
{ key: "Choose Next Question" , value: '' }
]);
getQuestionOptions.then(result => setOptions({
...options,
...res.data.map((item)=> ({
key: item.question,
value: item.question
})
)});
return <Field type="select" name={props.name}>
{options.map(option =>
<option key={option.key} value={option.value}>{option.key}</option>
)}
</Field>
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
this is the value that i am passing to options={next_questionOptions} but values of next_questionOptions changing after api call
so what I wanted is to dynamically change the value of options as soon as next_questionOptions updates after API call
Beta Was this translation helpful? Give feedback.
All reactions