-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update the documentation of the block editor and replace @wordpress/element with react #54908
Conversation
Size Change: +506 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great, thanks @youknowriad!
Left a few suggestions and typo fixes, let me know what you think.
@@ -18,7 +18,7 @@ Go ahead and create these files using the following snippets: | |||
**src/index.js:** | |||
|
|||
```js | |||
import { render } from '@wordpress/element'; | |||
import { render } from 'react-dom'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update that to reflect that we're now using React 18? Same for all other render()
instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There something subtle here is that we should do import { createRoot } from 'react-dom'
instead of import { createRoot } from 'react-com/client'
.
I think that's not great but it's because of how wp-scripts
works at the moment. Basically it transforms react-dom
imports to ReactDOM global variable and adds the wp dependency to the php script. And because of React generates the build we use, it works because createRoot
is actually ReactDOM.createRoot
in that build.
I think that's very confusing but I don't plan on solving that in this PR.
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
@@ -58,8 +58,8 @@ registerBlockType( 'gutenberg-examples/example-02-stylesheets', { | |||
{% Plain %} | |||
|
|||
```js | |||
( function ( blocks, element, blockEditor ) { | |||
var el = element.createElement; | |||
( function ( blocks, React, blockEditor ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is uppercase also how the default React scripts adds the window variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Follow-up to #54494
Related to #54074
What?
Since we switched the default pragma, this PR updates our documentation to clarify that plugin developers should use react directly instead of @wordpress/element
I also removed the internal WPComponent and WPElement types for clarity. It impacts a high number of files though.
Testing Instructions
This is mostly a documentation change, so nothing to test.