So I got App
which implements a componentDidMount
and render
.
App contains 2 components, one, an AutoComplete
input, and the other is a CardView
.
The plans is that once a user have chosen an item from the AutoComplete
list, to display it in the CardView
I wonder how would I trigger CardView
's render (i.e. setting it's state) from within the AutoComplete
event handler.
See the line that reads:
// willing to trigger CardView's render right here.
In the code below.
import React, { Component } from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import AutoComplete from 'material-ui/AutoComplete';
// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();
import './App.css';
class App extends Component {
constructor () {
super();
this.state = {accounts: []}
this.showAccount = this.showAccount.bind(this);
}
componentDidMount() {
this.setState({ accounts: [
{account_name: "foo", account_id: 1},
{account_name: "bar", account_id: 2}
]})
}
showAccount (value) {
// willing to trigger CardView's render right here.
}
render() {
return (
<MuiThemeProvider>
<div className="App">
<center>
<AutoComplete
floatingLabelText="account name"
filter={AutoComplete.caseInsensitiveFilter}
dataSource={this.state.accounts.map((account) => account.account_name)}
onUpdateInput={this.showAccount}
/></center>
<CardView />
</div>
</MuiThemeProvider>
);
}
}
export default App;