Button.onPress parameter not documented
See original GitHub issueDescription
The onPress
documentation for Button
does not explain what argument(s) may be passed.
I visited https://facebook.github.io/react-native/docs/button.html .
I expected to find documentation describing the argument passed to onPress
.
The documentation seems to suggest that no arguments are passed () => any
.
Reproduction Steps
Do the stuff in the description.
Sample Code
N/A
Solution
The documentation would be updated to show the parameter that is passed to the onPress
callback. Ideally, it’d link to the documentation of that parameter.
Additional Information
- React Native version: v0.46.0-rc.2 (current master)
- Platform: N/A
- Development Operating System: N/A
- Build tools: N/A
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Pass a string parameter in an onclick function - Stack Overflow
When I click on this button, I have an error that says that "Add is not defined". Since this function call works perfectly...
Read more >How Insidious React Native onPress Could Be - Bam Tech
The problem comes from the "secret" onPress parameter. Here is the ReactNative onPress type: ((event: GestureResponderEvent) => void) | ...
Read more >Button | Android Developers
If you are not satisfied with the default button style, you can customize it. For more details and code samples, see the Styling...
Read more >ASP.NET Core Razor components - Microsoft Learn
Learn how to create and use Razor components in Blazor apps, including guidance on Razor syntax, component naming, namespaces, and component ...
Read more >Actions - Storybook - JS.ORG
Thousands of teams use it for UI development, testing, and documentation. ... title: 'Button', component: Button, argTypes: { onClick: { action: 'clicked' } ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So should the Event not then be documented. I believe that is what @dpkirchner is getting at. As It did not appear to me that onPress was called with any parameters, where as it is apparently being called with an Event object. The next question is what is within the Event object.
Im interested in this, to see if theres a way for me to get an attribute from the button element that was pressed.
Or am I missing something?
For those who are curious, I was able to obtain the props of the button that was pressed via
This does not appear to be officially supported, so beware that it could change at anytime. To print out the structure of the event object you can use the following.
What is the likelihood that the ability to access the props of the item that was pressed would be accepted as an official feature in react-native. In ReactJS, I tend to use the data attributes in order to pass parameters to onClick functions without having to bind them. Something like:
Obviously I cant use data attributes in react-native, but something of a similar ilk would be nice. Should I create a separate issue for this?
The docs are generated from the source code. This is effectively calling http://facebook.github.io/react-native/docs/touchablewithoutfeedback.html#onpress, and from what I can see the only parameter passed is an Event https://github.com/facebook/react-native/blob/master/Libraries/Components/Touchable/TouchableWithoutFeedback.js#L119