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 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 ellatrix added the [Type] Code Quality Issues or PRs that relate to code quality label Dec 12, 2019
@ellatrix ellatrix requested a review from a team December 12, 2019 09:07
@ellatrix ellatrix mentioned this pull request Dec 12, 2019
6 tasks
@ellatrix ellatrix requested review from aduth and epiqueras December 12, 2019 09:11
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we refactor withInstanceId to use useInstanceId?

Anyway, this is cool 👍

@ellatrix
Copy link
Member Author

I'll adjust it. :)

@ellatrix
Copy link
Member Author

@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
Copy link
Contributor

@ellatrix maybe something like that

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

@ellatrix
Copy link
Member Author

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

@ellatrix
Copy link
Member Author

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

@ellatrix ellatrix merged commit e3dd420 into master Dec 12, 2019
@ellatrix ellatrix deleted the try/use-instance-id-alt branch December 12, 2019 16:10
@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
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants