我现在已经把头发撕成了几个小时了.
我有一个简单的Node服务器,它调用外部API来获取(大量的,像4+ MB)JSON位.我正在使用你作为样板文件的一个请求,直接来自Node文档:
const muniURL = `http://api.511.org/transit/vehiclemonitoring?api_key=${API_KEYS.API_KEY_511}&format=json&agency=sf-muni`;
http.get(muniURL, (res) => {
const statusCode = res.statusCode;
const contentType = res.headers['content-type'];
console.log('Status Code:', statusCode);
console.log('Content Type:', contentType);
let error;
if (statusCode !== 200) {
error = new Error(`Request Failed.\n` +
`Status Code: ${statusCode}`);
} else if (!/^application\/json/.test(contentType)) {
error = new Error(`Invalid content-type.\n` +
`Expected application/json but received ${contentType}`);
}
if (error) {
console.log(`Request error: ${error.message}`);
// consume response data to free up memory
res.resume();
return;
}
res.setEncoding('utf8');
let rawData = ''; …Run Code Online (Sandbox Code Playgroud) 我正在项目上使用React和Redux,我在实现启用/禁用按钮的功能时遇到问题.我已经能够:
但是,启用/禁用功能仍然不起作用,因为它似乎mapStateToProps并connect没有实际将状态映射到props.我正在追踪canSubmit,这在州内发生了变化,但却undefined在道具中.成功将状态映射到道具我错过了什么?
相关代码:
UserFormView.js
const mapStateToProps = (state) => ({
routerState: state.router,
canSubmit: state.canSubmit
});
const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(ActionCreators, dispatch)
});
class UserFormView extends React.Component {
Run Code Online (Sandbox Code Playgroud)
...
}
export default connect(mapStateToProps, mapDispatchToProps)(UserFormView);
Run Code Online (Sandbox Code Playgroud)
操作:
export function enableSubmit(payload) {
return {
type: ENABLE_SUBMIT,
payload: payload
};
}
export function disableSubmit(payload) {
return {
type: DISABLE_SUBMIT,
payload: payload
};
}
Run Code Online (Sandbox Code Playgroud)
Reducer(使用createReducer辅助函数):
const initialState = { …Run Code Online (Sandbox Code Playgroud) 我正在大型代码库中进行审核,并且需要搜索以查找与给定 prop 一起使用的组件的所有用途。我认为正则表达式在这里可能有用,但我不知道如何处理标记中潜在的换行符。我需要能够区分这两种用法,找到后者:
<Component
prop1="value1"
prop2={2}
/>
Run Code Online (Sandbox Code Playgroud)
<Component
prop1="value1"
targetProp={3}
prop2={2}
/>
Run Code Online (Sandbox Code Playgroud)
我不关心目标道具的值,只关心它存在于组件上。