https://github.com/peacechen/react-native-modal-selector
const [choices, setChoices] = useState<string[]>(["test"]);
const [choicesAnswer, setChoicesAnswer] = useState<string>("");
<ModalSelector
data={[...choices.map((e, i) => ({ key: i, label: e }))]}
initValue="정답지 선택"
cancelText="취소"
onChange={(option)=>{ setChoicesAnswer(option.label); }}
/>
이상하게 choices가 추가된 다음,, Selector onChange에서 setState를 시키면 랜더링 버그가 있는 것 같다.
💡대안
그냥 스크롤 핀을 사용하도록 하자..
https://github.com/react-native-picker/picker
const [choices, setChoices] = useState<string[]>(["test"]);
const [selectedLanguage, setSelectedLanguage] = useState();
<Picker
selectedValue={selectedLanguage}
onValueChange={itemValue => setSelectedLanguage(itemValue)}>
{choices.map((choice, idx) => <Picker.Item key={idx} label={`${choice}`} value={choice}/>)}
</Picker>