Quantcast
Channel: react-native fill the picker by mapping - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Jorge J V. L for react-native fill the picker by mapping

$
0
0

You should use ..!

import React, { useState, useEffect } from 'react';import {  StyleSheet,  View} from 'react-native';import axios from 'axios'import { Picker } from '@react-native-picker/picker';export default function App() {  const [state, setState] = useState([]);  const fetchAPI = () => {    const result = axios.post('http://www.example.com')      .then(response => {        const data = JSON.parse(JSON.stringify(response)).data.listaIncidencia;        setState(data)      })      .catch(error => {        console.error(error);      });    return result;  };  useEffect(() => {    fetchAPI();  }, []);   const [selectedValue, setSelectedValue] = useState("DEFAULD");  console.log(selectedValue)  return (<View><Picker        selectedValue={selectedValue}        onValueChange={(itemValue, itemIndex) => setSelectedValue(itemValue)}>{          state.map((item, index) => {            return <Picker.Item value={item.idMotivo} label={item.motivoDesc} key={index} />          })        }</Picker></View>  );}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images