testcafe-react-selectors icon indicating copy to clipboard operation
testcafe-react-selectors copied to clipboard

Support getReact for React Hooks

Open MMahmal opened this issue 5 years ago • 3 comments

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

MMahmal avatar May 29 '19 09:05 MMahmal

Hello, Thank you for sharing your idea with us. We will investigate the possibility of supporting React Hooks in the future.

LavrovArtem avatar May 30 '19 09:05 LavrovArtem

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.

MMahmal avatar May 31 '19 09:05 MMahmal

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.

miherlosev avatar Jun 03 '19 11:06 miherlosev

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.

github-actions[bot] avatar Dec 10 '22 01:12 github-actions[bot]

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.

github-actions[bot] avatar Dec 20 '22 01:12 github-actions[bot]