小编Vis*_*wat的帖子

为什么我们不能在Boact中将布尔值作为道具传递,它总是要求在我的代码中传递字符串

即使我已经应用了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)

reactjs redux

54
推荐指数
3
解决办法
5万
查看次数

为什么它说“next”没有在 redux 中间件代码中定义。中间件的下一个方法是否已弃用?

我收到此错误:

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)

javascript reactjs redux react-redux

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

React ES6中的子组件

我知道在过去的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)

或者这种方法还有其他方法吗?

reactjs

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

标签 统计

reactjs ×3

redux ×2

javascript ×1

react-redux ×1