Skip to main content

useBlocksTheme

useBlocksTheme is a React hook that provides the theme value when passed in the WordPressBlocksProvider component. The theme value is sourced by a theme.json file when using the fromThemeJson helper function.

Usage

First, define your theme in the WordPressBlocksProvider:

_app.js
import { WordPressBlocksProvider, fromThemeJson } from '@faustwp/blocks';
import blocks from 'src/wp-blocks';
import themeJson from './theme.json';
 
export function MyApp() {
  return (
    <WordPressBlocksProvider config={{blocks, theme: fromThemeJson(themeJson)}}>
      // Rest of your app
    </WordPressBlocksProvider>;
  )
}

Then, within your application, you can use useBlocksTheme to retrieve the specified theme:

const theme = useBlocksTheme();

Hey there! I'm an AI driven chat assistant here to help you with Faust.js! I'm trained on the documentation and can help you with coding tasks, learning, and more. What can I assist you with today?