小编Sem*_*den的帖子

类型错误:这是未定义的?

我无法到达 this.state 或者无法setState进入该componentDidMount函数。为什么?

import React from 'react';

class LoginApi extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            formNames: [],
        };
    }
    componentDidMount() {
        let apiKey = '###';
        window.JF.initialize({ apiKey: apiKey });
        window.JF.login(
            function success() {
                window.JF.getForms(function(response) {
                    for (var i in response) {
                        this.setState({ formNames: [...this.state.formNames, response[i]] });
                    }
                });
            },
            function error() {
                window.alert('Could not authorize user');
            }
        );
    }

    render() {
        return (
            <div className="initializeForm">
                <ul>
                    {this.state.formNames.map(forms => (
                        <li key={forms}>{forms}</li>
                    ))}
                </ul> …
Run Code Online (Sandbox Code Playgroud)

state this reactjs

4
推荐指数
1
解决办法
2607
查看次数

如何将 React 组件导出为 npm 包?Create-React-App 语法错误:意外的标记

我创建了反应应用程序,名称为“create-react-app-npm”。在 ./src/index.js 文件中,我导出了组件以在另一个项目中使用它的 npm 包。首先,我在我的主根目录中运行了这段代码。

npm run eject然后是我项目的下一部分

这是create-react-app-npm文件夹中的src/index.js

import React from 'react';
import './index.css';
import App from './App';

class ExportApp extends React.Component{
    render(){
        return(<App sayHi="hello There I am creating my first npm package"/>);
    }
}
export default ExportApp;


Run Code Online (Sandbox Code Playgroud)

这是 create-react-app-npm 文件夹中的 package.json 文件

{
  "name": "create-react-app-npm",
  "version": "0.1.0",
  "main": "src/index.js",
  "dependencies": {
    "@babel/core": "7.5.5",
    "@svgr/webpack": "4.3.2",
    "@typescript-eslint/eslint-plugin": "1.13.0",
    "@typescript-eslint/parser": "1.13.0",
    "babel-eslint": "10.0.2",
    "babel-jest": "^24.8.0",
    "babel-loader": "8.0.6",
    "babel-plugin-named-asset-import": "^0.3.3",
    "babel-preset-react-app": "^9.0.1",
    "camelcase": "^5.2.0",
    "case-sensitive-paths-webpack-plugin": "2.2.0",
    "css-loader": "2.1.1",
    "dotenv": "6.2.0", …
Run Code Online (Sandbox Code Playgroud)

javascript npm reactjs webpack create-react-app

4
推荐指数
1
解决办法
4640
查看次数

将 Jest 和 Cypress 与 Typescript 一起使用会导致断言和 JestMatchers 错误

在将 Cypress@10.0.3 与 Jest 一起使用时,我们面临断言和 JestMarchers 类型错误。为什么我们在某些项目中使用 Jest 和 Cypress@10.0.3 时会遇到 typecipt 错误?

typescript reactjs jestjs next.js cypress

4
推荐指数
1
解决办法
2323
查看次数