我是新来的反应者,我可以在const中样式化吗
这是我的代码
const initialStudentCounter =
'Students' + ' ' + JSON.stringify(studentCountInitial);
我需要设置此“ JSON.stringify(studentCountInitial)”的样式
我尝试过这种方法,但是没有用
const initialStudentCounter =
'Students' + ' ' + <span style={color : 'red'}>JSON.stringify(studentCountInitial)</span> ;
有人能帮助我吗
您不需要JSON.stringify
JSX。您确实需要将此元素与周围的元素一起插入到JSX中。您也不需要+
连接字符串了。
export default function App() {
const studentCountInitial = 4;
const initialStudentCounter = <div>Students <span style={{color : 'red'}}>{studentCountInitial}</span></div>;
return (
initialStudentCounter
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句