有什么方法可以解决javascript中找不到模块的错误吗?

bzzcjhmw  于 2022-12-21  发布在  Java
关注(0)|答案(1)|浏览(134)

我正在创建一个待办事项列表Web应用程序,但一些和这个错误发生在它说
编译有问题:
在./src/Components/TodoList.js中的错误6:0 - 57
未找到模块:错误:无法解析"C:\Users\91826\Desktop\WD\projects\待办事项列表\src\Components"中的. "/react/cjs/react. development "
谁能告诉我怎么解决这个问题。
TodoForm.js中的代码

import React, {useState} from "react";
export default function TodoForm(props){
  // state
  const [input, setInput] = useState("");

  const handleChange = e => {
    setInput(e.target.value)
    }

  const handleSubmit = (e) => {
    e.preventDefault();
    props.addTask({
      id: Math.floor(Math.random() * 1000000),
      text: input,
      isComplete: false
  })
    setInput('')
}
return(
    <form>
      <input type="text" placeholder="Add a todo" onChange={handleChange} className="todo-input" value={input} name="text"/>
      <button type="submit" onClick={handleSubmit} className= "todo-btn" >ADD TODO</button>
                                                 
</form>
);
}

TodoList.js中的代码

import React from 'react';
import {useState} from '.react/cjs/react.development';
 import TodoForm from './TodoForm'
export default function TodoList(){
   const [todos, setTodos] = useState([]);
  const addTask = task => {
    if (!task.text) {
      return
    }
     const newTodos = [task, ...todos];
    setTodos(newTodos);
}
  return <div>
     <TodoForm addTask={addTask} ></TodoForm>
   </div>;
}

App.js中的代码

import './App.css';
import TodoList from './Components/TodoList'
function App() {
  return (
    <div className="Todo-list-container">
     <TodoList/>
    </div>
  );
}

export default App;
wtlkbnrh

wtlkbnrh1#

useState应从React本身导入,因此这两行代码:

import React from 'react';
import {useState} from './react/cjs/react.development';

应改为

import React, { useState } from "react";

相关问题