我无法到达 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) 我创建了反应应用程序,名称为“create-react-app-npm”。在 ./src/index.js 文件中,我导出了组件以在另一个项目中使用它的 npm 包。首先,我在我的主根目录中运行了这段代码。
npm run eject
然后是我项目的下一部分
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)
{
"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) 在将 Cypress@10.0.3 与 Jest 一起使用时,我们面临断言和 JestMarchers 类型错误。为什么我们在某些项目中使用 Jest 和 Cypress@10.0.3 时会遇到 typecipt 错误?
reactjs ×3
cypress ×1
javascript ×1
jestjs ×1
next.js ×1
npm ×1
state ×1
this ×1
typescript ×1
webpack ×1