在React中未调用自定义钩子函数

时间:2019-11-14 20:00:58

标签: javascript reactjs react-native

我正在尝试调用我的on_touch_down()函数,但是我看不出为什么没有调用它。

  

/screens/RecipeScreen.js

self.canvas.clear()
  

/components/RecipeSearch.js

self.canvas.before.clear()
  

/hooks/usePlants.js

Label

起初我以为也许我打电话给fetchPlants太早了(在import usePlants from '../hooks/usePlants'; // Call our custom hook const [fetchPlants, plantResults] = usePlants(); // ...other code... <RecipeSearch recipeSearch={recipeSearch} onRecipeSearchChange={setRecipeSearch} onRecipeSearchSubmit={() => fetchPlants(recipeSearch)} /> 处于任何状态之前),但我不这么认为,因为它仍然能够正确const RecipeSearch = ({ onRecipeSearchChange, onRecipeSearchSubmit, recipeSearch, }) => { return ( console.log(recipeSearch); // This prints out nicely... <View> <View> <TextInput placeholder='Find a plant...' value={recipeSearch} onChangeText={onRecipeSearchChange} onEndEditing={onRecipeSearchSubmit} /> </View> </View> ); };

1 个答案:

答案 0 :(得分:1)

更新,一切正常。当我使用iOS模拟器进行测试时,我需要在计算机上按“ ENTER”键,因为我正在使用React Native onEndEditing 道具。