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

Fix the jslint warning from useSelect usage #651

Merged
merged 1 commit into from
May 23, 2024
Merged

Conversation

pbking
Copy link
Contributor

@pbking pbking commented May 23, 2024

Fix the jslint warning (or infinate loop error when fixed) from useSelect usage.

Pulled the subfolder value (once) and set it in the initial call to useState rather than using that state in the useSelect when fetching the current theme's subfolder.

Fixes jslint warning and everything works as expected.

(To test, create a new theme using the Editor interface. It should be created in the same subfolder as the currently activated theme)

Comment on lines +35 to +42
const subfolder = useSelect( ( select ) => {
const stylesheet = select( 'core' ).getCurrentTheme().stylesheet;
if ( stylesheet.lastIndexOf( '/' ) > 1 ) {
return stylesheet.substring( 0, stylesheet.lastIndexOf( '/' ) );
}
return '';
}, [] );

Copy link
Member

Choose a reason for hiding this comment

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

I've never tried setting initial state based on a value provided by a function called within the same component, but it doesn't seem to be a problem... so I'm inclined to approve this, albeit hesitantly

@pbking pbking merged commit 3b69810 into trunk May 23, 2024
2 checks passed
@pbking pbking deleted the fix/subfolder-fetching branch May 23, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants