您可以使用getter函数:
class ElementBuilder extends Component { constructor(props) { super(props); this.state = this.initialState; } get initialState() { return { title: 'Testing', size: 100, color: '#4d96ce', }; } resetBuilder() { this.setState(this.initialState); }}或只是一个变量:
constructor(props) { super(props); this.initialState = { title: 'Testing', size: 100, color: '#4d96ce', }; this.state = this.initialState;}


