Advanced JSX Tracking #2752
-
I'm new to the framework and trying to wrap my head around the "Advanced JSX Tracking". https://panda-css.com/docs/concepts/recipes#advanced-jsx-tracking Why do you need to track the usage? Isn't the usage tracked by consumers importing the built |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This concept is only relevant if your recipe lives in the panda.config not directly in your app. Recipes can be created in two ways: directly in your app (cva/sva) or in the config. Recipes defined in the config are 'smart' recipes, meaning only the variants you use will be generated. This also means you can have as many variants as you want, but you pay for the vairants you use in CSS (saving some KB in CSS) Let's say you create a recipe called 'tabs', and you add it to the config. defineConfig({
theme: {
extend: {
recipes: {
// tabs recipe
tabs: {
base: {},
variants: {
size: { sm: {}, md: {} }
},
},
},
},
},
}) Then in your app, you consume that recipe in a JSX component. import { tabs } from 'styled-system/recipes'
const Tabs = (props) => {
const [recipeProps, restProps] = tabs.splitVariantProps(props)
const className = tabs(recipeProps)
return <div className={className} />
} Because the recipe was called <Tabs size="sm" /> Does this make sense? Now, let's say instead of import { tabs } from 'styled-system/recipes'
// recipe doesn't match component name
const Foo = (props) => {
const [recipeProps, restProps] = tabs.splitVariantProps(props)
const className = tabs(recipeProps)
return <div className={className} />
} This breaks the inference semantics, and Panda doesn't know that So you need to hint the compiler that tabs: {
jsx: ['Tabs', 'Foo']
} With that, Panda will pick this up and when you do <Foo size="sm" /> Hope you get it now? |
Beta Was this translation helpful? Give feedback.
This concept is only relevant if your recipe lives in the panda.config not directly in your app.
Recipes can be created in two ways: directly in your app (cva/sva) or in the config.
Recipes defined in the config are 'smart' recipes, meaning only the variants you use will be generated. This also means you can have as many variants as you want, but you pay for the vairants you use in CSS (saving some KB in CSS)
Let's say you create a recipe called 'tabs', and you add it to the config.