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

New hook: useInstanceId (alternative) #19091

Merged
merged 12 commits into from Dec 12, 2019
Merged

New hook: useInstanceId (alternative) #19091

merged 12 commits into from Dec 12, 2019

Conversation

@ellatrix
Copy link
Member

ellatrix commented Dec 12, 2019

Description

Alternative to #19071, which now works exactly as withInstanceId. The difference with #19071 is that ids are linked to the function they are used with. Hooks that use useInstanceId will have to pass the parent function name.

Usage:

function SomeComponent() {
 	const instanceId = useInstanceId( SomeComponent );
 	...
 }

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR. .
ellatrix and others added 9 commits Dec 11, 2019
Co-Authored-By: Andrew Duthie <andrew@andrewduthie.com>
@ellatrix ellatrix requested a review from WordPress/gutenberg-core Dec 12, 2019
@ellatrix ellatrix mentioned this pull request Dec 12, 2019
6 of 6 tasks complete
@ellatrix ellatrix requested review from aduth and epiqueras Dec 12, 2019
Copy link
Contributor

youknowriad left a comment

Should we refactor withInstanceId to use useInstanceId?

Anyway, this is cool 👍

@ellatrix

This comment has been minimized.

Copy link
Member Author

ellatrix commented Dec 12, 2019

I'll adjust it. :)

@ellatrix

This comment has been minimized.

Copy link
Member Author

ellatrix commented Dec 12, 2019

@youknowriad Actually, I don't think we can simply use useInstanceId inside withInstanceId, because we're not provided with a reference to the function. The both work different, though provide the same thing.

@youknowriad

This comment has been minimized.

Copy link
Contributor

youknowriad commented Dec 12, 2019

@ellatrix maybe something like that

const withInstanceId = ( Wrapped ) => (props) => {
    const  instanceId = useInstanceId(Wrapped);
    return <Wrapped instanceId={instanceId} {...props} />;
} 
@ellatrix

This comment has been minimized.

Copy link
Member Author

ellatrix commented Dec 12, 2019

@youknowriad Oh right, I forgot we have WrappedComponent... Stupid me. :)

@ellatrix

This comment has been minimized.

Copy link
Member Author

ellatrix commented Dec 12, 2019

Alright, this works great and no need to modify ids in test snapshots! Merging.

@ellatrix ellatrix merged commit e3dd420 into master Dec 12, 2019
2 checks passed
2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Passed
Details
@ellatrix ellatrix deleted the try/use-instance-id-alt branch Dec 12, 2019
@youknowriad youknowriad added this to the Gutenberg 7.2 milestone Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.