小编Rag*_*ani的帖子

react-简写形式的setState

你能写吗

    let firstNameValid = this.state.firstNameValid;

    firstNameValid = value.length >= 1; 

    this.setState({ firstNameValid, firstNameValid,}) 
Run Code Online (Sandbox Code Playgroud)

作为简短语法

this.setState({ firstNameValid})  
Run Code Online (Sandbox Code Playgroud)

我已经尝试了上面的代码,似乎工作正常。只想知道它是否会有副作用?

state setstate reactjs

3
推荐指数
1
解决办法
1076
查看次数

使用 webpack ProvidePlugin 全局导入 javascript 文件

我有一个进行网络调用的功能,我希望该功能在全球范围内可用,而不必每次需要使用该功能时都导入它

请求.js

import 'whatwg-fetch';

/**
 * Parses the JSON returned by a network request
 *
 * @param  {object} response A response from a network request
 *
 * @return {object}          The parsed JSON from the request
 */
function parseJSON(response) {
  if (response.status === 204 || response.status === 205) {
    return null;
  }
  return response.json();
}

/**
 * Checks if a network request came back fine, and throws an error if not
 *
 * @param  {object} response   A response from a network …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs webpack react-boilerplate webpack-plugin

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