i wanna access button value in react native, in pure javascript it look like :
const checkingStuff = (e) => console.log(e.target.value)
<button onclick={checkingStuff} > this is the value </button>.
how to achieve the same thing in react native?
edit : please answer in react native, not react js, because
<Button
onPress={checkingStuff}
title='lalala123'/>
give me 'undefined'.
event handlers give you inherent access to the event through the function. Unless specifically setting state within the DOM, there's no need to do an inline arrow function. You can simply reference the function like so:
const checkingStuff = (e) => { console.log(e.target.value) }
<button onClick={checkingStuff} > Set state and add your {value} like so </button>
I don't know excatly what you try to achieve, however you should access the event directly in the input instead of the button. For TextInput in React Native, the changed text is passed as a single string argument to the callback handler.
You can try this
const [text, onChangeText] = useState("")
const onPress = () => {
console.log(text)
}
return (
<>
<TextInput value={text} onChangeText={onChangeText}>
<Button onPress={onPress}/>
</>
)
You can get like this:
const checkingStuff = (e) => console.log(e.target.value)
<button onclick={(e) => checkingStuff(e)} > this is the value </button>