Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref prop is not working for Button component of New React native element lib (@rneui/base & @rneui/themed) #3885

Open
1 task done
shelendrasingh opened this issue Feb 1, 2024 · 2 comments

Comments

@shelendrasingh
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Explain what you did

ref prop is not working for Button component

`
import { withTheme } from '@rneui/themed';
import { Button as LibraryButton } from '@rneui/base';
..........

const Button = (props) => {
const { containerStyle, theme, ...rest } = props;
const buttonStyles = styles(containerStyle);
const fetchedStyle = buttonColors(props);
const { titleStyle, icon, ...buttonStyle } = fetchedStyle;
return <LibraryButton icon={icon} {...rest} {...buttonStyles} buttonStyle={buttonStyle} titleStyle={titleStyle} />;
};
....
export default withTheme(Button);
`
we are sending ref as prop in Button Component like below code.

Versions using :
"@rneui/base": "^4.0.0-rc.8",
"@rneui/themed": "^4.0.0-rc.8"

`
const submitButtonRef = React.useRef();
........

`

Expected behavior

Currently Getting: we are getting undefined for submitButtonRef?.current

Expected: we should get submitButtonRef?.current value.

Describe the bug

ref prop is not working for Button component

Steps To Reproduce

Click on 'Button'
not getting ref.current after pressing on the Button  we are getting undefined for ref.

Screenshots

No response

Your Environment

`npx @rneui/envinfo`
  ```
    Output from `npx @rneui/envinfo` goes here.
  ```

@shelendrasingh shelendrasingh changed the title ref prop is not working for Button component ref prop is not working for Button component of New React native element lib (@rneui/base & @rneui/themed) Feb 1, 2024
@arpitBhalla
Copy link
Member

Hey, the example code you provided needs to be wrapped in forwardRef. Let me know if it helps.

const Button = forwardRef((props,ref) => {
	const { containerStyle, theme, ...rest } = props;
	const buttonStyles = styles(containerStyle);
	const fetchedStyle = buttonColors(props);
	const { titleStyle, icon, ...buttonStyle } = fetchedStyle;
	return <LibraryButton ref={ref} icon={icon} {...rest} {...buttonStyles} buttonStyle={buttonStyle} titleStyle={titleStyle} />;
});

export default withTheme(Button);

@shelendrasingh
Copy link
Author

Hey, the example code you provided needs to be wrapped in forwardRef. Let me know if it helps.

const Button = forwardRef((props,ref) => {
	const { containerStyle, theme, ...rest } = props;
	const buttonStyles = styles(containerStyle);
	const fetchedStyle = buttonColors(props);
	const { titleStyle, icon, ...buttonStyle } = fetchedStyle;
	return <LibraryButton ref={ref} icon={icon} {...rest} {...buttonStyles} buttonStyle={buttonStyle} titleStyle={titleStyle} />;
});

export default withTheme(Button);

@arpitBhalla Thanks for reply but We have already tried this solution but it did not work. It is working fine if We are importing Button Component from 'react-native'. It is not working if We are importing Button component from '@rneui/base'.

Kindly help on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants