即使我已经应用了propType验证,我的编辑器在为hasvacancyprop 传递布尔值时会抛出错误.这是我所看到的:
错误:'SyntaxError:JSX值应该是表达式或带引号的JSX文本'
我知道我正在传递'hasvacancy'prop的字符串类型值,但是我需要做什么,所以我可以通过prop传递布尔值或其他数据类型.
import React from 'react';
import { render } from 'react-dom';
class VacancySign extends React.Component{
render() {
console.log('------------hasvacancy------', this.props.hasvacancy);
if(this.props.hasvacancy) {
return(
<div>
<p>Vacancy</p>
</div>
);
} else {
return(
<div>
<p>No-Vacancy</p>
</div>);
}
}
}
VacancySign.propTypes ={
hasvacancy: React.PropTypes.bool.isRequired
}
render(<VacancySign hasvacancy='false'/> ,
document.getElementById('root'));
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
index.js?dadc:6Uncaught TypeError: next is not a function
ReactJS 中中间件使用的下一个方法是否已被弃用,或者我是否错误地使用了它?
import { applyMiddleware, combineReducers , createStore } from 'redux';
const logger =(store) => (next) => (action) => {
console.log('middle-ware called');
next(action);
}
const reducer=(state ,action)=>{
if(action.type=='INC'){
console.log('a-----------------',action);
return state+action.payload;
}
else
return state; };
const store=createStore(reducer ,1 ,applyMiddleware(logger()));
store.subscribe(()=>{
console.log('store changed',store.getState()) });
store.dispatch({type :'INC' ,payload : 10}); store.dispatch({type :'INC' ,payload : 10});
Run Code Online (Sandbox Code Playgroud) 我知道在过去的React版本中我们可以制作这样的子组件.
var MyFormComponent = React.createClass({ ... });
MyFormComponent.Row = React.createClass({ ... });
MyFormComponent.Label = React.createClass({ ... });
MyFormComponent.Input = React.createClass({ ... });
Run Code Online (Sandbox Code Playgroud)
但我想知道如何在React ES6中创建子组件.它是否使用语法
class Row Extends MyFormComponent , Component {}
Run Code Online (Sandbox Code Playgroud)
或者这种方法还有其他方法吗?