你能写吗
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)
我已经尝试了上面的代码,似乎工作正常。只想知道它是否会有副作用?
我有一个进行网络调用的功能,我希望该功能在全球范围内可用,而不必每次需要使用该功能时都导入它
请求.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)