Console.log在react native中给出了关于dispatch_instances的很长的输出

b4qexyjb  于 2023-05-01  发布在  React
关注(0)|答案(1)|浏览(207)

我在react native中创建了一个简单的应用程序,其中文本在按钮按下后显示在控制台中。按下按钮后,我在控制台中收到一些意外的输出。请告诉我有什么可以改变的,或者我在这里做错了什么?

  1. import { useState } from 'react';
  2. import { StyleSheet, Text, View, Button, TextInput } from "react-native";
  3. export default function App() {
  4. const [enteredGoalText, setenteredGoalText] = useState();
  5. function goalInputHandler(enteredText) {
  6. setenteredGoalText(enteredText);
  7. }
  8. function addGoalHandler() {
  9. console.log(enteredGoalText);
  10. }
  11. return (
  12. <View style={styles.appContainer}>
  13. <View style={styles.inputContainer}>
  14. <TextInput
  15. style={styles.textInput}
  16. placeholder="Your course goal!!"
  17. onChange={goalInputHandler}
  18. />
  19. <Button title="Add goal" onPress={addGoalHandler} />
  20. </View>
  21. <View style={styles.goalsContainer}>
  22. <Text>List of goals....</Text>
  23. </View>
  24. </View>
  25. );
  26. }
  27. const styles = StyleSheet.create({
  28. appContainer: {
  29. flex: 1,
  30. paddingTop: 50,
  31. paddingHorizontal: 16,
  32. },
  33. inputContainer: {
  34. flex: 1,
  35. flexDirection: "row",
  36. justifyContent: "space-between",
  37. alignItems: "center",
  38. marginBottom: 24,
  39. borderBottomWidth: 1,
  40. borderBottomColor: "#cccccc",
  41. },
  42. textInput: {
  43. borderWidth: 1,
  44. borderColor: "#cccccc",
  45. width: "70%",
  46. marginRight: 8,
  47. padding: 8,
  48. },
  49. goalsContainer: {
  50. flex: 5,
  51. },
  52. });

我在控制台中得到以下输出

  1. "_dispatchInstances": {
  2. "_debugHookTypes": null,
  3. "_debugNeedsRemount": false,
  4. "_debugOwner": {
  5. "_debugHookTypes": [Array],
  6. "_debugNeedsRemount": false,
  7. "_debugOwner": [FiberNode],
  8. "_debugSource": undefined,
  9. "actualDuration": 0.3320891857147217,
  10. "actualStartTime": 829945578.402573,
  11. "alternate": [FiberNode],
  12. "child": [FiberNode],
  13. "childLanes": 0,
  14. "deletions": null,
  15. "dependencies": null,
  16. "elementType": [Function InternalTextInput],
  17. "flags": 8388613,
  18. "index": 0,
  19. "key": null,
  20. "lanes": 0,
  21. "memoizedProps": [Object],
  22. "memoizedState": [Object],
  23. "mode": 2,
  24. "pendingProps": [Object],
  25. "ref": null,
  26. "return": [FiberNode],
  27. "selfBaseDuration": 0.2843759059906006,
  28. "sibling": null,
  29. "stateNode": null,
  30. "subtreeFlags": 516,
  31. "tag": 0,
  32. "treeBaseDuration": 0.31690704822540283,
  33. "type": [Function InternalTextInput],
  34. "updateQueue": [Object]
  35. },
  36. "_debugSource": undefined,
  37. "actualDuration": 0.022422194480895996,
  38. "actualStartTime": 829945578.710574,
  39. "alternate": {
  40. "_debugHookTypes": null,
  41. "_debugNeedsRemount": false,
  42. "_debugOwner": [FiberNode],
  43. "_debugSource": undefined,
  44. "actualDuration": 0.021181941032409668,
  45. "actualStartTime": 829945576.637425,
  46. "alternate": [Circular],
  47. "child": null,
  48. "childLanes": 0,
  49. "deletions": null,
  50. "dependencies": null,
  51. "elementType": "RCTSinglelineTextInputView",
  52. "flags": 516,
  53. "index": 0,
  54. "key": null,
  55. "lanes": 0,
  56. "memoizedProps": [Object],
  57. "memoizedState": null,
  58. "mode": 2,
  59. "pendingProps": [Object],
  60. "ref": [Function forwardRef],
  61. "return": [FiberNode],
  62. "selfBaseDuration": 0.01284801959991455,
  63. "sibling": null,
  64. "stateNode": [ReactNativeFiberHostComponent],
  65. "subtreeFlags": 0,
  66. "tag": 5,
  67. "treeBaseDuration": 0.01284801959991455,
  68. "type": "RCTSinglelineTextInputView",
  69. "updateQueue": null
  70. },
  71. "child": null,
  72. "childLanes": 0,
  73. "deletions": null,
  74. "dependencies": null,
  75. "elementType": "RCTSinglelineTextInputView",
  76. "flags": 516,
  77. "index": 0,
  78. "key": null,
  79. "lanes": 0,
  80. "memoizedProps": {
  81. "accessibilityState": [Object],
  82. "accessible": true,
  83. "allowFontScaling": true,
  84. "autoComplete": undefined,
  85. "caretHidden": undefined,
  86. "dataDetectorTypes": undefined,
  87. "editable": undefined,
  88. "focusable": true,
  89. "forwardedRef": null,
  90. "keyboardType": undefined,
  91. "mostRecentEventCount": 19,
  92. "onBlur": [Function _onBlur],
  93. "onChange": [Function _onChange],
  94. "onChangeSync": null,
  95. "onClick": [Function onClick],
  96. "onContentSizeChange": undefined,
  97. "onFocus": [Function _onFocus],
  98. "onKeyPressSync": undefined,
  99. "onResponderGrant": [Function onResponderGrant],
  100. "onResponderMove": [Function onResponderMove],
  101. "onResponderRelease": [Function onResponderRelease],
  102. "onResponderTerminate": [Function onResponderTerminate],
  103. "onResponderTerminationRequest": [Function onResponderTerminationRequest],
  104. "onScroll": [Function _onScroll],
  105. "onSelectionChange": [Function _onSelectionChange],
  106. "onSelectionChangeShouldSetResponder": [Function emptyFunctionThatReturnsTrue],
  107. "onStartShouldSetResponder": [Function onStartShouldSetResponder],
  108. "placeholder": "Your course goal!!",
  109. "rejectResponderTermination": true,
  110. "returnKeyType": undefined,
  111. "selection": null,
  112. "style": [Object],
  113. "submitBehavior": "blurAndSubmit",
  114. "text": "",
  115. "textContentType": undefined,
  116. "underlineColorAndroid": "transparent"
  117. },
  118. "memoizedState": null,
  119. "mode": 2,
  120. "pendingProps": {
  121. "accessibilityState": [Object],
  122. "accessible": true,
  123. "allowFontScaling": true,
  124. "autoComplete": undefined,
  125. "caretHidden": undefined,
  126. "dataDetectorTypes": undefined,
  127. "editable": undefined,
  128. "focusable": true,
  129. "forwardedRef": null,
  130. "keyboardType": undefined,
  131. "mostRecentEventCount": 19,
  132. "onBlur": [Function _onBlur],
  133. "onChange": [Function _onChange],
  134. "onChangeSync": null,
  135. "onClick": [Function onClick],
  136. "onContentSizeChange": undefined,
  137. "onFocus": [Function _onFocus],
  138. "onKeyPressSync": undefined,
  139. "onResponderGrant": [Function onResponderGrant],
  140. "onResponderMove": [Function onResponderMove],
  141. "onResponderRelease": [Function onResponderRelease],
  142. "onResponderTerminate": [Function onResponderTerminate],
  143. "onResponderTerminationRequest": [Function onResponderTerminationRequest],
  144. "onScroll": [Function _onScroll],
  145. "onSelectionChange": [Function _onSelectionChange],
  146. "onSelectionChangeShouldSetResponder": [Function emptyFunctionThatReturnsTrue],
  147. "onStartShouldSetResponder": [Function onStartShouldSetResponder],
  148. "placeholder": "Your course goal!!",
  149. "rejectResponderTermination": true,
  150. "returnKeyType": undefined,
  151. "selection": null,
  152. "style": [Object],
  153. "submitBehavior": "blurAndSubmit",
  154. "text": "",
  155. "textContentType": undefined,
  156. "underlineColorAndroid": "transparent"
  157. },
  158. "ref": [Function forwardRef],
  159. "return": {
  160. "_debugHookTypes": null,
  161. "_debugNeedsRemount": false,
  162. "_debugOwner": [FiberNode],
  163. "_debugSource": undefined,
  164. "actualDuration": 0.04571723937988281,
  165. "actualStartTime": 829945578.690279,
  166. "alternate": [FiberNode],
  167. "child": [Circular],
  168. "childLanes": 0,
  169. "deletions": null,
  170. "dependencies": null,
  171. "elementType": [Object],
  172. "flags": 0,
  173. "index": 0,
  174. "key": null,
  175. "lanes": 0,
  176. "memoizedProps": [Object],
  177. "memoizedState": null,
  178. "mode": 2,
  179. "pendingProps": [Object],
  180. "ref": null,
  181. "return": [FiberNode],
  182. "selfBaseDuration": 0.018931031227111816,
  183. "sibling": null,
  184. "stateNode": null,
  185. "subtreeFlags": 516,
  186. "tag": 10,
  187. "treeBaseDuration": 0.032531142234802246,
  188. "type": [Object],
  189. "updateQueue": null
  190. },
  191. "selfBaseDuration": 0.01360011100769043,
  192. "sibling": null,
  193. "stateNode": {
  194. "_children": [Array],
  195. "_internalFiberInstanceHandleDEV": [Circular],
  196. "_nativeTag": 3,
  197. "clear": [Function clear],
  198. "getNativeRef": [Function getNativeRef],
  199. "isFocused": [Function isFocused],
  200. "setSelection": [Function setSelection],
  201. "viewConfig": [Object]
  202. },
  203. "subtreeFlags": 0,
  204. "tag": 5,
  205. "treeBaseDuration": 0.01360011100769043,
  206. "type": "RCTSinglelineTextInputView",
  207. "updateQueue": null
  208. }, "_dispatchListeners": [Function _onChange], "_targetInst": {
  209. "_debugHookTypes": null,
  210. "_debugNeedsRemount": false,
  211. "_debugOwner": {
  212. "_debugHookTypes": [Array],
  213. "_debugNeedsRemount": false,
  214. "_debugOwner": [FiberNode],
  215. "_debugSource": undefined,
  216. "actualDuration": 0.3320891857147217,
  217. "actualStartTime": 829945578.402573,
  218. "alternate": [FiberNode],
  219. "child": [FiberNode],
  220. "childLanes": 0,
  221. "deletions": null,
  222. "dependencies": null,
  223. "elementType": [Function InternalTextInput],
  224. "flags": 8388613,
  225. "index": 0,
  226. "key": null,
  227. "lanes": 0,
  228. "memoizedProps": [Object],
  229. "memoizedState": [Object],
  230. "mode": 2,
  231. "pendingProps": [Object],
  232. "ref": null,
  233. "return": [FiberNode],
  234. "selfBaseDuration": 0.2843759059906006,
  235. "sibling": null,
  236. "stateNode": null,
  237. "subtreeFlags": 516,
  238. "tag": 0,
  239. "treeBaseDuration": 0.31690704822540283,
  240. "type": [Function InternalTextInput],
  241. "updateQueue": [Object]
  242. },
  243. "_debugSource": undefined,
  244. "actualDuration": 0.022422194480895996,
  245. "actualStartTime": 829945578.710574,
  246. "alternate": {
  247. "_debugHookTypes": null,
  248. "_debugNeedsRemount": false,
  249. "_debugOwner": [FiberNode],
  250. "_debugSource": undefined,
  251. "actualDuration": 0.021181941032409668,
  252. "actualStartTime": 829945576.637425,
  253. "alternate": [Circular],
  254. "child": null,
  255. "childLanes": 0,
  256. "deletions": null,
  257. "dependencies": null,
  258. "elementType": "RCTSinglelineTextInputView",
  259. "flags": 516,
  260. "index": 0,
  261. "key": null,
  262. "lanes": 0,
  263. "memoizedProps": [Object],
  264. "memoizedState": null,
  265. "mode": 2,
  266. "pendingProps": [Object],
  267. "ref": [Function forwardRef],
  268. "return": [FiberNode],
  269. "selfBaseDuration": 0.01284801959991455,
  270. "sibling": null,
  271. "stateNode": [ReactNativeFiberHostComponent],
  272. "subtreeFlags": 0,
  273. "tag": 5,
  274. "treeBaseDuration": 0.01284801959991455,
  275. "type": "RCTSinglelineTextInputView",
  276. "updateQueue": null
  277. },
  278. "child": null,
  279. "childLanes": 0,
  280. "deletions": null,
  281. "dependencies": null,
  282. "elementType": "RCTSinglelineTextInputView",
  283. "flags": 516,
  284. "index": 0,
  285. "key": null,
  286. "lanes": 0,
  287. "memoizedProps": {
  288. "accessibilityState": [Object],
  289. "accessible": true,
  290. "allowFontScaling": true,
  291. "autoComplete": undefined,
  292. "caretHidden": undefined,
  293. "dataDetectorTypes": undefined,
  294. "editable": undefined,
  295. "focusable": true,
  296. "forwardedRef": null,
  297. "keyboardType": undefined,
  298. "mostRecentEventCount": 19,
  299. "onBlur": [Function _onBlur],
  300. "onChange": [Function _onChange],
  301. "onChangeSync": null,
  302. "onClick": [Function onClick],
  303. "onContentSizeChange": undefined,
  304. "onFocus": [Function _onFocus],
  305. "onKeyPressSync": undefined,
  306. "onResponderGrant": [Function onResponderGrant],
  307. "onResponderMove": [Function onResponderMove],
  308. "onResponderRelease": [Function onResponderRelease],
  309. "onResponderTerminate": [Function onResponderTerminate],
  310. "onResponderTerminationRequest": [Function onResponderTerminationRequest],
  311. "onScroll": [Function _onScroll],
  312. "onSelectionChange": [Function _onSelectionChange],
  313. "onSelectionChangeShouldSetResponder": [Function emptyFunctionThatReturnsTrue],
  314. "onStartShouldSetResponder": [Function onStartShouldSetResponder],
  315. "placeholder": "Your course goal!!",
  316. "rejectResponderTermination": true,
  317. "returnKeyType": undefined,
  318. "selection": null,
  319. "style": [Object],
  320. "submitBehavior": "blurAndSubmit",
  321. "text": "",
  322. "textContentType": undefined,
  323. "underlineColorAndroid": "transparent"
  324. },
  325. "memoizedState": null,
  326. "mode": 2,
  327. "pendingProps": {
  328. "accessibilityState": [Object],
  329. "accessible": true,
  330. "allowFontScaling": true,
  331. "autoComplete": undefined,
  332. "caretHidden": undefined,
  333. "dataDetectorTypes": undefined,
  334. "editable": undefined,
  335. "focusable": true,
  336. "forwardedRef": null,
  337. "keyboardType": undefined,
  338. "mostRecentEventCount": 19,
  339. "onBlur": [Function _onBlur],
  340. "onChange": [Function _onChange],
  341. "onChangeSync": null,
  342. "onClick": [Function onClick],
  343. "onContentSizeChange": undefined,
  344. "onFocus": [Function _onFocus],
  345. "onKeyPressSync": undefined,
  346. "onResponderGrant": [Function onResponderGrant],
  347. "onResponderMove": [Function onResponderMove],
  348. "onResponderRelease": [Function onResponderRelease],
  349. "onResponderTerminate": [Function onResponderTerminate],
  350. "onResponderTerminationRequest": [Function onResponderTerminationRequest],
  351. "onScroll": [Function _onScroll],
  352. "onSelectionChange": [Function _onSelectionChange],
  353. "onSelectionChangeShouldSetResponder": [Function emptyFunctionThatReturnsTrue],
  354. "onStartShouldSetResponder": [Function onStartShouldSetResponder],
  355. "placeholder": "Your course goal!!",
  356. "rejectResponderTermination": true,
  357. "returnKeyType": undefined,
  358. "selection": null,
  359. "style": [Object],
  360. "submitBehavior": "blurAndSubmit",
  361. "text": "",
  362. "textContentType": undefined,
  363. "underlineColorAndroid": "transparent"
  364. },
  365. "ref": [Function forwardRef],
  366. "return": {
  367. "_debugHookTypes": null,
  368. "_debugNeedsRemount": false,
  369. "_debugOwner": [FiberNode],
  370. "_debugSource": undefined,
  371. "actualDuration": 0.04571723937988281,
  372. "actualStartTime": 829945578.690279,
  373. "alternate": [FiberNode],
  374. "child": [Circular],
  375. "childLanes": 0,
  376. "deletions": null,
  377. "dependencies": null,
  378. "elementType": [Object],
  379. "flags": 0,
  380. "index": 0,
  381. "key": null,
  382. "lanes": 0,
  383. "memoizedProps": [Object],
  384. "memoizedState": null,
  385. "mode": 2,
  386. "pendingProps": [Object],
  387. "ref": null,
  388. "return": [FiberNode],
  389. "selfBaseDuration": 0.018931031227111816,
  390. "sibling": null,
  391. "stateNode": null,
  392. "subtreeFlags": 516,
  393. "tag": 10,
  394. "treeBaseDuration": 0.032531142234802246,
  395. "type": [Object],
  396. "updateQueue": null
  397. },
  398. "selfBaseDuration": 0.01360011100769043,
  399. "sibling": null,
  400. "stateNode": {
  401. "_children": [Array],
  402. "_internalFiberInstanceHandleDEV": [Circular],
  403. "_nativeTag": 3,
  404. "clear": [Function clear],
  405. "getNativeRef": [Function getNativeRef],
  406. "isFocused": [Function isFocused],
  407. "setSelection": [Function setSelection],
  408. "viewConfig": [Object]
  409. },
  410. "subtreeFlags": 0,
  411. "tag": 5,
  412. "treeBaseDuration": 0.01360011100769043,
  413. "type": "RCTSinglelineTextInputView",
  414. "updateQueue": null
  415. }, "bubbles": undefined, "cancelable": undefined, "currentTarget": {
  416. "_children": [],
  417. "_internalFiberInstanceHandleDEV": {
  418. "_debugHookTypes": null,
  419. "_debugNeedsRemount": false,
  420. "_debugOwner": [FiberNode],
  421. "_debugSource": undefined,
  422. "actualDuration": 0.022422194480895996,
  423. "actualStartTime": 829945578.710574,
  424. "alternate": [FiberNode],
  425. "child": null,
  426. "childLanes": 0,
  427. "deletions": null,
  428. "dependencies": null,
  429. "elementType": "RCTSinglelineTextInputView",
  430. "flags": 516,
  431. "index": 0,
  432. "key": null,
  433. "lanes": 0,
  434. "memoizedProps": [Object],
  435. "memoizedState": null,
  436. "mode": 2,
  437. "pendingProps": [Object],
  438. "ref": [Function forwardRef],
  439. "return": [FiberNode],
  440. "selfBaseDuration": 0.01360011100769043,
  441. "sibling": null,
  442. "stateNode": [Circular],
  443. "subtreeFlags": 0,
  444. "tag": 5,
  445. "treeBaseDuration": 0.01360011100769043,
  446. "type": "RCTSinglelineTextInputView",
  447. "updateQueue": null
  448. },
  449. "_nativeTag": 3,
  450. "clear": [Function clear],
  451. "getNativeRef": [Function getNativeRef],
  452. "isFocused": [Function isFocused],
  453. "setSelection": [Function setSelection],
  454. "viewConfig": {
  455. "Commands": [Object],
  456. "Constants": [Object],
  457. "Manager": "SinglelineTextInputViewManager",
  458. "NativeProps": [Object],
  459. "baseModuleName": "RCTBaseTextInputView",
  460. "bubblingEventTypes": [Object],
  461. "directEventTypes": [Object],
  462. "uiViewClassName": "RCTSinglelineTextInputView",
  463. "validAttributes": [Object]
  464. }
  465. }, "defaultPrevented": undefined, "dispatchConfig": {
  466. "phasedRegistrationNames": {
  467. "bubbled": "onChange",
  468. "captured": "onChangeCapture"
  469. }
  470. }, "eventPhase": undefined, "isDefaultPrevented": [Function functionThatReturnsFalse], "isPropagationStopped": [Function functionThatReturnsFalse], "isTrusted": undefined, "nativeEvent": {
  471. "eventCount": 20,
  472. "target": 3,
  473. "text": "T"
  474. }, "target": {
  475. "_children": [],
  476. "_internalFiberInstanceHandleDEV": {
  477. "_debugHookTypes": null,
  478. "_debugNeedsRemount": false,
  479. "_debugOwner": [FiberNode],
  480. "_debugSource": undefined,
  481. "actualDuration": 0.022422194480895996,
  482. "actualStartTime": 829945578.710574,
  483. "alternate": [FiberNode],
  484. "child": null,
  485. "childLanes": 0,
  486. "deletions": null,
  487. "dependencies": null,
  488. "elementType": "RCTSinglelineTextInputView",
  489. "flags": 516,
  490. "index": 0,
  491. "key": null,
  492. "lanes": 0,
  493. "memoizedProps": [Object],
  494. "memoizedState": null,
  495. "mode": 2,
  496. "pendingProps": [Object],
  497. "ref": [Function forwardRef],
  498. "return": [FiberNode],
  499. "selfBaseDuration": 0.01360011100769043,
  500. "sibling": null,
  501. "stateNode": [Circular],
  502. "subtreeFlags": 0,
  503. "tag": 5,
  504. "treeBaseDuration": 0.01360011100769043,
  505. "type": "RCTSinglelineTextInputView",
  506. "updateQueue": null
  507. },
  508. "_nativeTag": 3,
  509. "clear": [Function clear],
  510. "getNativeRef": [Function getNativeRef],
  511. "isFocused": [Function isFocused],
  512. "setSelection": [Function setSelection],
  513. "viewConfig": {
  514. "Commands": [Object],
  515. "Constants": [Object],
  516. "Manager": "SinglelineTextInputViewManager",
  517. "NativeProps": [Object],
  518. "baseModuleName": "RCTBaseTextInputView",
  519. "bubblingEventTypes": [Object],
  520. "directEventTypes": [Object],
  521. "uiViewClassName": "RCTSinglelineTextInputView",
  522. "validAttributes": [Object]
  523. }
  524. }, "timeStamp": 1682788547472, "type": undefined

预期控制台输出:单击按钮后输入框中的文本

dgiusagp

dgiusagp1#

传递给onChange处理程序的参数是Event;你会希望使用onChangeText,它会传递新的文本:

  1. <TextInput
  2. style={styles.textInput}
  3. placeholder="Your course goal!!"
  4. onChange={setenteredGoalText}
  5. />

相关问题