文本用作状态变量但未声明

text is used as a state variable but not declared

下面的例子来自docs on useReducer

状态变量text用于

onChangeText={(text) => {
      dispatch({ type: 'first', value: text })
    }}

但据我所知,它并没有事先在任何地方声明。我错过了什么吗?

import React, { useReducer } from 'react'
import { View, Text, TextInput } from 'react-native'

function reducer(state, action) {
  switch (action.type) {
    case 'first':
      return { ...state, first: action.value }
    case 'last':
      return { ...state, last: action.value }
  }
}

export default function App() {
  const [state, dispatch] = useReducer(reducer, { first: '', last: '' })

  return (
    <View>
      <TextInput
        style={{ fontSize: 32 }}
        placeholder="First"
        value={state.first}
        onChangeText={(text) => {
          dispatch({ type: 'first', value: text })
        }}
      />
      <TextInput
        style={{ fontSize: 32 }}
        placeholder="Last"
        value={state.last}
        onChangeText={(text) => {
          dispatch({ type: 'last', value: text })
        }}
      />
      <Text style={{ fontSize: 32 }}>
        Hello {state.first} {state.last}
      </Text>
    </View>
  )
}

如果这是一件微不足道的事情,我很抱歉让你担心。我是这个环境的新手..!!这个社区很棒。

'text' 是新闻发布会。
读这个:
https://reactnative.dev/docs/view#props
https://reactnative.dev/docs/pressevent