[wp-trac] [WordPress Trac] #45271: Can't enqueue WordPress 5.0 builtin reactjs
WordPress Trac
noreply at wordpress.org
Tue Nov 6 02:08:26 UTC 2018
#45271: Can't enqueue WordPress 5.0 builtin reactjs
-----------------------------------------+-------------------------
Reporter: CantoThemes | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.0
Component: Script Loader | Version: 5.0
Severity: normal | Resolution:
Keywords: reporter-feedback has-patch | Focuses: javascript
-----------------------------------------+-------------------------
Comment (by nerrad):
@CantoThemes what may be happening in your case is `react` and `react-dom`
are being printed AFTER your script requiring them. What you need to do
is register 'react' and 'react-dom' as dependencies on your script and
then just enqueue your script in `load_assets`.
So something like:
{{{
wp_register_script( 'my-script-handle', $my_script_location, array(
'react', 'react-dom' ), $version, $in_footer );
}}}
Then in your `load_scripts` callback just call `wp_enqueue_script( 'my-
script-handle' )`.
This will ensure that your script is printed AFTER react and react-dom on
the page.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45271#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list