I am trying to write a method to render buttons dynamically and am trying to avoid code repetition by using renderButton method. I cannot find a solid solution anywhere to this problem can anyone help? I am fairly new to react native
export default class DialogBoxStory extends PureComponent {
state = { isVisible: false, type: 'confirm' }
hide (type) {
return (payload = '') => {
this.setState({ isVisible: false })
console.debug(`hide ${type}`, payload)
}
}
show (type) {
return (payload) => {
this.setState({ isVisible: true, type })
console.debug(`show ${type}`, payload)
}
}
renderButtons () {
return [ 'confirm', 'alert', 'input' ]
.map((type) => (
<Button
title={`show ${type} dialog`}
type="primary"
onPress={this.show(type)}
/>
))
}
render () {
const options = {
title: text('title', 'Test Title', 'props'),
message: text('message', lorem, 'props'),
onOkPress: this.hide('onOkPress'),
onCancelPress: this.hide('onCancelPress'),
isVisible: this.state.isVisible,
type: this.state.type,
onRequestClose: this.hide('onRequestClose'),
}
return (
<Fragment>
<DialogBox {...options} />
{this.renderButtons}
</Fragment>
)
}
}

{this.renderButtons()}- Mayank Shukla{this.renderButtons()}? does it work after that? - Mayank Shuklareturnhere?return <Button title={show ${type} dialog} type="primary" onPress={this.show(type)} />- Just code