React里面使用props报错

#1

##源码

import React, { Component } from 'react';

class Ceshi extends Component {
  props = {
    title: '这是默认的title属性值'
  }
  render(){
    console.log(this.props);

    return <b>{this.props.title}</b>
  }
}

export default Ceshi;


// 组件调用方式
// <Ceshi title="设置的标题" />

##报错信息
warning.js:44Warning: Ceshi(…): When calling super() in Ceshi, make sure to pass up the same props that your component’s constructor was passed.warning

不太明白是什么原因造成的,求助!!!

#2

你的component中的constructor也设置了props,但是和你当前设置的props的值不一样造成的错误(你当前的是title,但是你的Component中的props不是title)

#3

export default class Hello extends React.Component {
constructor(props) {
super(props);
}

render() {  		
  	return (
  	 	<h1 id="hello" style={{textAlign: 'center'}} className="animated flipInX">Hi, I am a {this.props.text}</h1>
  	);
}

}

#4

好的 谢谢你

#5

谢谢

#6

你为什么在class里面放props?props应该是由父组件提供给你的 在类的内部要用state或者其他自定义属性