Hello everyone !
I’m new on adalo, i start to code a composant for an application but i have a little bug.
When i click on the buttons i have made, the action is made many times.
I don’t understand why can you help me ?
there is my code :
this is the index.js
import React, { Component } from ‘react’
import { Text, View, StyleSheet, Button} from ‘react-native’
class PlusMoins extends Component {
constructor(props) {
super(props);
this.state = {
count: 1
};
}
render() {
const { color, ButtonColor, FirstButtonText, SecondButtonText, action} = this.props
return (
<Button title={ FirstButtonText } color={ ButtonColor } onPress={() => { if(this.state.count != 1){ this.setState({ count: this.state.count - 1 })}}} ></Button>
<input style={{textAlign:'center',width:30, color, padding : 5,margin :5, backgroundColor : '#FFFFFF' ,borderColor: '#FFFFFF', borderWidth: 1, }} type="number" value={this.state.count} onChange={this.handleChange} />
<Button title={ SecondButtonText } color={ ButtonColor } onPress={() => this.setState({ count: this.state.count + 1 })}></Button>
<Button title={ "Add to cart"} onPress={ action(this.state.count) }></Button>
</View>
)
}
}
const styles = StyleSheet.create({
wrapper: {
flexDirection: ‘row’,
display: ‘flex’,
alignItems: ‘center’,
justifyContent: ‘center’,
}
})
export default PlusMoins
And there is the Manifest.json
{
“displayName”: “PlusMoins”,
“defaultWidth”: 200,
“defaultHeight”: 100,
“components”: “./index.js”,
“icon”: “./example-thumbnail.png”,
“props”: [
{
“name”: “color”,
“displayName”: “Color”,
“type”: “color”,
“default”: “#00A898”
},
{
“name”: “ButtonColor”,
“displayName”: “ButtonColor”,
“type”: “color”,
“default”: “#00A898”
},
{
“name”: “FirstButtonText”,
“displayName”: “FirstButtonText”,
“type”: “Text”,
“default”: “-”
},
{
“name”: “SecondButtonText”,
“displayName”: “SecondButtonText”,
“type”: “Text”,
“default”: “+”
},
{
“name”: “action”,
“displayName”: “Add to cart”,
“type”: “action”,
“arguments”: [
{
“type”: “number”,
“displayName”: “arg”
}
]
}
]
}