I'm trying to get two different cards in one with a switcher button :
As you can see here this is the result I want plus I've already got the console outputting the state of the switcher which is comming from the switcher component.
/* ************************************* */
/* ******** 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;
Hope this makes evident what I'm trying to do. As you can see here :
<div>
{this.newState ?
<SearchByType />
: <SearchExtended />}
</div>
this would be my if condition.
this :
handleSwitch(newState) {
console.log(newState);
}
prints out true or false when I click on the button.
I don't know what should be in the constructor and in the variable section and if to call newState within render with "this.newState" or "newState".
I tried changing my imports to :
import { SearchByType } from '../CardCollection/SearchByType';
import { SearchExtended } from '../CardCollection/SearchExtended';
but that did not help and it shouldn't be that anyways since these are export defaut
I'm very lost.