jeudi 2 avril 2020

How to map array into checkbox for React Native [TypeScript]?

I am new to React Native. I am currently using TypeScript for my React Native project. Right now, I am having a difficulty on how to map array into checkbox. Below is my json file:

{ 
   "stud_name": "Adam",
   "sex": "male",
   "attendance": false,
   "eligibility": false
}

I would like to map attendance and eligibility inside the checkbox. Below is my React Native code for the checkbox.

export const StudentRegisterExam: React.FC<Props> = ({}) => {
  const StudentData = useContext(StudentStoreContext);

  const firstRender = useRef(true);
  useEffect(() => {
    if (firstRender.current) {
      firstRender.current = false;
      return;
    }
    if (response !== undefined) {
      if (response.status === 201 || response.status === 200) {
        StudentData.details = {
           name: response.data.name,
           sex: response.data.sex,
           eligibility: response.data.eligibility,
           attendance: response.data.attendance
       };
     }
   }
 }, [response]);

return (
      <View>
        <Text>{StudentData.response.name}</Text>
        <Text>{StudentData.response.sex}</Text>
        <CheckBox /> <- how should I write {StudentData.response.eligibility} into checkbox
        <CheckBox />
      </View>
 );

Thank you in advance. For the StudentData, I created a file name CompanyStore.ts inside my store folder.




Aucun commentaire:

Enregistrer un commentaire