Created
March 12, 2024 07:39
-
-
Save RoelofWobben/2c3dac36e95f5868b9b71ded18604ee7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Retrieves the translation of text. | |
* | |
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/ | |
*/ | |
import { __ } from '@wordpress/i18n'; | |
/** | |
* React hook that is used to mark the block wrapper element. | |
* It provides all the necessary props like the class name. | |
* | |
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops | |
*/ | |
import { useBlockProps } from '@wordpress/block-editor'; | |
import apiFetch from '@wordpress/api-fetch'; | |
import React, { useState, useEffect } from "react"; | |
/** | |
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files. | |
* Those files can contain any CSS code that gets applied to the editor. | |
* | |
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css | |
*/ | |
import './editor.scss'; | |
useEffect(() => { | |
async function fetchCategories() { | |
try { | |
const response = await apiFetch({ | |
path: "/wp/v2/categories", | |
}); | |
console.log(response); // response is already resolved to JSON | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
fetchCategories(); | |
}, []); | |
/** | |
* The edit function describes the structure of your block in the context of the | |
* editor. This represents what the editor will render when the block is used. | |
* | |
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit | |
* | |
* @return {Element} Element to render. | |
*/ | |
export default async function Edit() { | |
return ( | |
<p { ...useBlockProps() }> | |
{ __( | |
"test", | |
'rw-filter-categories' | |
) } | |
</p> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment