I'm trying to render 3 buttons with different text and action onPress(). I've found this solution on stackoverflow but it didn't work for me.
class App extends React.Component {
state = {
loading: false,
isModalVisible: false
};
toggleModal = () => {
this.setState({ isModalVisible: !this.state.isModalVisible });
};
testfunc = () => {
console.log("this f***ng WORKS");
};
renderButtons = () => {
const buttons = [
{
title: "I have no clear direction",
action: () => console.log("this WORKS")
},
{ title: "I have some idea of what i want", action: () => this.testfunc },
{ title: "I know exactly what i want", action: this.toggleModal }
];
buttons[0].action();
buttons[1].action;
buttons[2].action;
return buttons.map((i, index) => {
return (
<View style={{ marginTop: 20, width: "100%" }} key={index}>
<OnboardingButton
title={i.title}
loading={this.state.loading}
onPress={() => i.action}
/>
</View>
);
});
};
}
I used console.log() just for testing. As output when this screen is rendered I'm getting this:
this WORKS
When I click on any button nothing happens.
onPress()was overridden in<OnboardingButton>. Thanks for the answer anyway!