testcafe-react-selectors
testcafe-react-selectors copied to clipboard
Support getReact for React Hooks
Hello, First I wanted to say thanks for the amazing works!
And second, I wanted to ask if someone was already working on the support of React Hooks. Because at the moment I cannot get the state or the props of a component using Hooks.
Thank you for your time :) Cheers, Mehdi
Hello, Thank you for sharing your idea with us. We will investigate the possibility of supporting React Hooks in the future.
Thanks for the quick reply!
If I have time I would like to offer my contribution. Do you guys already have a process in place?
Cheers.
Hi @MMahmal
Thank you for your interest in the project.
Accessing the props
values should work correctly now.
See the following example:
//Component tree:
<Container>
<Child/>
</Container>
//Components classes:
function Child(props) {
return <span>{props.propName}</span>
}
function Container() {
const [value, setState] = useState(0);
return (
<div><Child propName={value}/></div>
)
}
//Test code:
ReactSelector('Child').getReact(({props}) => props.propName);
It's not easy to support hooks for the functional state
function myComponent() {
const [value, setValue] = useState(0);
return <div>{value}</div>
}
because we set variable names.
React DevTools has an experimental support of the React Hooks. But it doesn't work correctly in my machine.
Anyway, if you want to implement or improve support of React Hooks - you are welcome. Create a pull request and we will review it.
This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.
We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.