简体   繁体   English

将样式道具传递给反应组件

[英]Passing a style prop to react component

I have a typescript Next.js app that's misbehaving (or I'm just stupid).我有一个 typescript Next.js 应用程序行为不端(或者我只是愚蠢)。
There's a component <CluckHUD props="styles.Moon" /> that is supposed to pass the theme as a css classname.有一个组件<CluckHUD props="styles.Moon" />应该将主题作为 css 类名传递。 This is supposed to customize the theme on a per-page basis.这应该在每页的基础上自定义主题。

Component here组件在这里

export default function CluckHUD({ theme }: { theme: any }) {
    return (
        <nav className={{...theme}}>
            <ul className={styles.navbarNav}>

(Yes they all have closing tags, and yes I imported the component in the first file) (是的,它们都有结束标签,是的,我在第一个文件中导入了组件)

Except when everything runs, the class is [object Object] .除了一切运行时, class 是[object Object] Am I missing something, or is the whole approach wrong?我错过了什么,还是整个方法都错了?

There is an easy way to solve your problem.有一种简单的方法可以解决您的问题。
Please use classnames node module in your project.请在您的项目中使用类名节点模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM