Reputation: 33
const addvariableSlider = [
'Discount Rate',
'Total Volume',
'R&D'
]
class HelloMessage extends React.Component {
dis(){
return (
< Range
value={this.state.discountRateRange}
onChange={this.discountChange}
onAfterChange={this.discountAfterChange}
/>
)
}
totVol(){
return (
< Range
value={this.state.totalVolRateRange}
onChange={this.totalVolChange}
onAfterChange={this.totalVolAfterChange}
/>
)
}
onSliderVarClick = (e) => {
if (e.value == "Discount Rate") {
this.dis()
}
if(e.value=="Total Volume"){
this.totVol();
}
}
render() {
return (
<div>
<Dropdown options={addvariableSlider} onChange={this.onSliderVarClick} value="" placeholder="Add Variable" /><br />
</div>
);
}
}
whatever the functions i called based on dropdown value, how to show those returned components dynamically in render function? after showing in render i can be able to work on those onchange and onAfterChange events
Upvotes: 0
Views: 769
Reputation: 21883
Continuing the logic of @Harish Soni, this example simplifies and brings code closer to the working component:
class HelloMessage extends React.Component {
constructor(){
this.state= {
discountRateRange = 'something'
}
}
discountChange = () => {
alert('discountChange called')
}
discountAfterChange = () => {
alert('discountAfterChange called')
}
render() {
return (
<div>
<Range
value={this.state.discountRateRange}
onChange={this.discountChange}
onAfterChange={this.discountAfterChange}
/>
</div>
);
}
}
Upvotes: 1
Reputation: 1896
This the correct way to do it.
These points to follow:
arrow
function to get rid of the binding thing.Then TRY THIS UPDATED ANSWER
class HelloMessage extends React.Component {
discountChange = () => {
alert('onChange called')
}
add = () => {
return (< Range
value={this.state.discountRateRange}
onChange={this.discountChange}
onAfterChange={this.discountAfterChange}
/>
)
}
render() {
return (
<div>
{this.add()}
</div>
);
}
}
Upvotes: 2