Using the sx prop with TypeScript
#1723
Replies: 1 comment
-
|
The StyleX transform can compile the For example, add something like import type { StyleXStyles } from '@stylexjs/stylex';
declare module 'react' {
interface HTMLAttributes<T> {
sx?: StyleXStyles;
}
interface SVGAttributes<T> {
sx?: StyleXStyles;
}
}Then this should type-check: import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
button: { color: 'red' },
});
export function App() {
return <button sx={styles.button}>Click</button>;
}The bundler plugin still has to run the StyleX transform; If you do not want a global JSX augmentation, the typed fallback is still the explicit form: <button {...stylex.props(styles.button)}>Click</button> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've tried using the
sxprop on JSX elements but hit a TypeScript errorProperty 'sx' does not exist on type 'DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>'. None of the examples appear to use the prop, but I was wondering if a type needs to be augmented to allow the prop to be used.Is there additional configuration needed to use the
sxprop within a TypeScript project?Example: https://stackblitz.com/edit/github-exkhdnrp?file=src%2FApp.tsx
Beta Was this translation helpful? Give feedback.
All reactions