| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | */ |
| 4 | 4 | import apiFetch from '@wordpress/api-fetch'; |
| 5 | 5 | import { ToggleControl } from '@wordpress/components'; |
| 6 | 6 | import domReady from '@wordpress/dom-ready'; |
| 7 | -import { render, useState, WPElement } from '@wordpress/element'; | |
| 7 | +import { createRoot, render, useState, WPElement } from '@wordpress/element'; | |
| 8 | 8 | import { __ } from '@wordpress/i18n'; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Window dependencies. |
| @@ -56,8 +56,9 @@ | ||
| 56 | 56 | className="index-toggle" |
| 57 | 57 | disabled={isLoading} |
| 58 | 58 | label={isChecked ? __('On', 'elasticpress') : __('Off', 'elasticpress')} |
| 59 | 59 | onChange={onChange} |
| 60 | + __nextHasNoMarginBottom | |
| 60 | 61 | /> |
| 61 | 62 | ); |
| 62 | 63 | }; |
| 63 | 64 | |
| @@ -69,15 +70,22 @@ | ||
| 69 | 70 | const init = () => { |
| 70 | 71 | const toggles = document.getElementsByClassName('index-toggle'); |
| 71 | 72 | |
| 72 | 73 | for (const toggle of toggles) { |
| 73 | - render( | |
| 74 | + const element = ( | |
| 74 | 75 | <ElasticPressToggleControl |
| 75 | 76 | blogId={toggle.dataset.blogId} |
| 76 | 77 | isDefaultChecked={toggle.checked} |
| 77 | - />, | |
| 78 | - toggle.parentElement, | |
| 78 | + /> | |
| 79 | 79 | ); |
| 80 | + | |
| 81 | + if (typeof createRoot === 'function') { | |
| 82 | + const root = createRoot(toggle.parentElement); | |
| 83 | + | |
| 84 | + root.render(element); | |
| 85 | + } else { | |
| 86 | + render(element, toggle.parentElement); | |
| 87 | + } | |
| 80 | 88 | } |
| 81 | 89 | }; |
| 82 | 90 | |
| 83 | 91 | domReady(init); |