【发布时间】:2017-09-06 01:26:24
【问题描述】:
正如您在此处看到的,这是我想要的结果,而且我已经让控制台输出了切换器组件的切换器状态。
/* ************************************* */
/* ******** IMPORTS ******** */
/* ************************************* */
import React, { Component } from 'react';
import { Card, CardBlock, CardTitle, Button, InputGroup, Input } from 'reactstrap';
import ProviderInfos from '../ProviderInfos/ProviderInfos';
import Switcher from '../Switcher/Switcher';
import SearchByType from '../CardCollection/SearchByType';
import SearchExtended from '../CardCollection/SearchExtended';
/* ************************************* */
/* ******** VARIABLES ******** */
/* ************************************* */
const status = {
newState: false,
callBack: () => {},
};
/* ************************************* */
/* ******** COMPONENT ******** */
/* ************************************* */
class InterfaceCardComponent extends Component {
// constructor with state and bind of switch state
constructor(props) {
super(props);
//this.handleChange = this.handleChange.bind(this);
//onChange={newState.handleChange.bind(this)}
//this.newState = {this.state.bind(this)};
}
// switch state
handleSwitch(newState) {
console.log(newState);
}
render() {
return (
<Card>
<div id="cardInterface">
<div className="title-switcher-block">
<CardTitle>Search by Type</CardTitle>
<Switcher callBack={this.handleSwitch} />
<CardTitle>Extended search</CardTitle>
</div>
<div>
{/* I cheated here for the picture and put the contents within "SearchByType" */}
{this.newState ?
<SearchByType />
: <SearchExtended />}
</div>
</div>
</Card>
);
}
}
/* ************************************* */
/* ******** EXPORTS ******** */
/* ************************************* */
export default InterfaceCardComponent;
希望这能说明我想要做什么。正如你在这里看到的:
<div>
{this.newState ?
<SearchByType />
: <SearchExtended />}
</div>
这将是我的 if 条件。
这个:
handleSwitch(newState) {
console.log(newState);
}
当我点击按钮时打印出真假。
我不知道构造函数和变量部分应该是什么,以及是否使用“this.newState”或“newState”在渲染中调用 newState。
我尝试将导入更改为:
import { SearchByType } from '../CardCollection/SearchByType';
import { SearchExtended } from '../CardCollection/SearchExtended';
但这并没有帮助,反正也不应该是这样,因为这些是export defaut
我很迷茫。
【问题讨论】:
标签: reactjs