在哪里定义道具以在我的 React 应用程序中访问它们?

pyt*_*dha 1 javascript reactjs

不幸的是,我无法解决我在开发to do list应用程序时面临的问题。请问以下代码有什么问题?

function handleSubmit(e){
    e.preventDefault();
    //alert('Moin');
    props.addTask("Say hello!");
}

function Form(props){
    return(
        <form onSubmit={handleSubmit}> 
            <h2 className="label-wrapper">
                <label htmlFor="new-todo-input" className="label__lg">
                    What needs to be done?
    ...


   
Run Code Online (Sandbox Code Playgroud)

出现以下错误

编译失败。

./src/components/Form.js 第 8 行:'props' 未定义 no-undef

Huw*_*Huw 5

function Form(props){

  function handleSubmit(e){
      e.preventDefault();
      //alert('Moin');
      props.addTask("Say hello!");
  }

    return(
        <form onSubmit={handleSubmit}> 
            <h2 className="label-wrapper">
                <label htmlFor="new-todo-input" className="label__lg">
                    What needs to be done?
Run Code Online (Sandbox Code Playgroud)

这与变量的范围有关,您可以在此处阅读更多信息