第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

TypeError:未定義不是一個(gè)對(duì)象在React Native中評(píng)估'addTodo

TypeError:未定義不是一個(gè)對(duì)象在React Native中評(píng)估'addTodo

瀟湘沐 2023-07-14 15:01:14
我收到異常 TypeError: undefined is not an object (evaluating 'addTodo(title, description).then') 該函數(shù)工作正常并且狀態(tài)更新正常,但它沒有按預(yù)期工作。添加Todo.js:import { useNavigation } from '@react-navigation/native';import React , {useContext, useState} from 'react';import { View } from 'react-native';import { Input , Button} from 'react-native-elements';import { TextInput } from 'react-native-gesture-handler';import {cardContext} from '../contextApi/cardContext';const NewTodoInput = () =>{const { addTodo } = useContext(cardContext);const navigation = useNavigation();const [title , setTitle] = useState()const [description , setDescription] = useState()const handleOnSubmit = ()=>{        addTodo(title,description)    .then((data)=>{        navigation.navigate('TodoApp');        console.log('Added Succesfully : ' + data);    })    .catch((e)=>{console.log(e)});}return (    <View>    <Input     placeholder = 'Title'    onChangeText= {(val)=>{setTitle(val)}}    />    <Input     placeholder = 'Your todo'    multiline = {true}    onChangeText = {(val) => {setDescription(val)}}    />    <Button         buttonStyle= {{backgroundColor : 'black'}}        title = 'Submit'        onPress = {handleOnSubmit}                    />    </View>)}export default NewTodoInput ;上下文.jsimport React , {createContext, useState} from 'react'export const cardContext = createContext();const Data = (props) =>{    const [data , setData] = useState(        //todo Add id to the data        [            {title : 'This is title 1' , Description : 'this is description 1'},            {title : 'This is title 2' , Description : 'this is description 2'},            {title : 'This is title 3' , Description : 'this is description 3'},            {title : 'This is title 4' , Description : 'this is description 4'},        ]            ) 
查看完整描述

1 回答

?
慕妹3242003

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果您想更改 addTodo 以使其返回評(píng)論中所述的承諾,那么這里是:


const addTodo = (title , description) =>{

   setData( [...data , {title : title, Description : description}] )

   return new Promise((resolve, reject) => {

       resolve("data") // Do something here preferable what you need inside .then()

                      })

}


查看完整回答
反對(duì) 回復(fù) 2023-07-14
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)