小编Dar*_*mer的帖子

类型错误:react__WEBPACK_IMPORTED_MODULE_2___default(...) 不是函数。我该如何解决这个问题?

当我收到以下错误时,我正在使用 React。

TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function

我该如何解决这个问题?我已经添加了下面的代码。

import React from 'react';
import LoginForm from './loginForm'
import useState from "react"

function LoginPage(){
    const[details, setDetails] = useState({
        username: '',
        password: ''
    });
    function handleChange(event){
        const updatedDetails = {...details, [event.target.name]: event.target.value};
        setDetails(updatedDetails)
    }
    return(<LoginForm details={details} onChange={handleChange}/>)
};

export default LoginPage;
Run Code Online (Sandbox Code Playgroud)

另一个组件是:-

import React from "react";
import 'bootstrap/dist/css/bootstrap.min.css';
import { Jumbotron, Container } from 'reactstrap';
import { Button, Form, FormGroup, Label, Input, FormText } from 'reactstrap';

function FormPage(props){
  return (
    <Jumbotron fluid> …
Run Code Online (Sandbox Code Playgroud)

javascript typeerror node.js reactjs webpack

7
推荐指数
1
解决办法
2万
查看次数

当我更改在 React 中传递给它的道具时,组件不会更新

我有一个具有子组件的功能组件。子组件显示一些通过 props 从父组件传递给它的文本。当我更改父组件中的文本并将其向下传递时,子组件仍保留旧文本。

下面是父组件 MainPage 的最小可重现示例。

function MainPage(){
    let text = "This is the original text";
    setTimeout(function(){ text = "This is the new text" }, 3000);
    return(<DisplayText text={text} />);
}
Run Code Online (Sandbox Code Playgroud)

下面是显示文本。

function DisplayText(props){
    return(<p>{props.text}</p>)
}
Run Code Online (Sandbox Code Playgroud)

如何更新子组件,使其在 3 秒后显示“这是新文本”而不​​是“这是原始文本”?

提前致谢!

javascript parent-child rerender reactjs react-props

5
推荐指数
1
解决办法
1万
查看次数

如何在 React 中修复“TypeError: results.map is not a function”

function Results(props) {
  var results = props.results;
  return (
    <>
      <table>
        <thead>
          <tr>
            <th>Book Name</th>
            <th>Author</th>
            <th>S.no</th>
            <th>Series Name</th>
            <th>Type</th>
            <th>Genre</th>
            <th>Kindle/Real</th>
          </tr>
        </thead>
        <tbody>
          {results.map(result => {
            return (
              <tr key={result.name}>
                <td>{result.name}</td>
                <td>{result.author}</td>
                <td>{result.sno}</td>
                <td>{result.series}</td>
                <td>{result.type}</td>
                <td>{result.genre}</td>
                <td>{result.kindeReal}</td>
              </tr>
            );
          })}
        </tbody>
      </table>
    </>
  );
}
Run Code Online (Sandbox Code Playgroud)

当我尝试渲染上述 com 组件时,出现错误:

类型错误:results.map 不是函数

结果变量是一个对象数组,类似于:

[{"type":1},{"type":0},{"type":2}]
Run Code Online (Sandbox Code Playgroud)

但是,当我使用 .map 函数时,它返回错误!它显然是一个数组,为什么我不能使用它?

这是 console.log(results) 的输出。

[{"Book_Name":"Time Riders","Author":"Alex Scarrow","S_no":1,"Series_Name":"Time Riders","Fiction_Non_fiction_Companion_Prequel":"Fiction","Genre":"Sci-fi/Mystery/Thriller","Kindle_Real":"Real"},{"Book_Name":"Day of the Predator ","Author":"Alex Scarrow","S_no":2,"Series_Name":"Time Riders","Fiction_Non_fiction_Companion_Prequel":"Fiction","Genre":"Sci-fi/Mystery/Thriller","Kindle_Real":"Real"},{"Book_Name":"The Doomsday Code","Author":"Alex Scarrow","S_no":3,"Series_Name":"Time Riders","Fiction_Non_fiction_Companion_Prequel":"Fiction","Genre":"Sci-fi/Mystery/Thriller","Kindle_Real":"Real"},{"Book_Name":"The Eternal War","Author":"Alex Scarrow","S_no":4,"Series_Name":"Time Riders","Fiction_Non_fiction_Companion_Prequel":"Fiction","Genre":"Sci-fi/Mystery/Thriller","Kindle_Real":"Real"},{"Book_Name":"Gates of Rome","Author":"Alex …
Run Code Online (Sandbox Code Playgroud)

javascript arrays object reactjs array.prototype.map

1
推荐指数
1
解决办法
2万
查看次数

Python 中的 Package.json

有什么方法可以为我的 python 文件夹创建 package.json 文件,就像在 NodeJS (npm) 中一样?

例如:如果我使用 pip 导入 Flask,我希望 Flask 出现在 package.json 文件中。它不必是 JSON,也可以是 .txt 文件。

仅供参考:我想要该文件,以便我可以在传输文件或将文件夹上传到 GitHub 时立即安装所有依赖项

谢谢!

python import module package.json

0
推荐指数
1
解决办法
1063
查看次数