私はスイッチャーボタンで一つに二つの異なるカードを取得しようとしている:これは私が望む結果であるあなたがここに見ることができるように ReactJS条件コンポーネント表示
プラス私はすでに出力コンソールを持っていますスイッチャコンポーネントから来ているスイッチャの状態。
/* ************************************* */
/* ******** 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>
これは私の条件です。
この:私はボタンをクリックしたときに
handleSwitch(newState) {
console.log(newState);
}
は、真または偽を出力します。
"this.newState"または "newState"でレンダリング内のnewStateを呼び出すかどうか、コンストラクタと変数セクションに何が含まれるべきか分かりません。
私はに私の輸入を変えてみました:
import { SearchByType } from '../CardCollection/SearchByType';
import { SearchExtended } from '../CardCollection/SearchExtended';
が、それは助けにはならなかった、それはこれらがexport defaut
をしているとにかくので、私は非常に迷ってしまいましたことをすべきではありません。
キャッチされないエラー:要素の種類が無効です:文字列(組み込みコンポーネント用)またはクラス/ functi on(複合コンポーネントの場合)ですが、未定義です。あなたが定義したファイルからコンポーネントをエクスポートするのを忘れた可能性があります。 'InterfaceCardComponent'のレンダリングメソッドをチェックしてください。 – tatsu