import '@emotion/react';
declare module '@emotion/react' {
export interface Theme {
colors: {
primaryColor: string;
accentColor: string;
};
}
}
Run Code Online (Sandbox Code Playgroud)
import { Theme, ThemeProvider } from '@emotion/react';
const theme: Theme = {
colors: {
accentColor: 'hotpink',
primaryColor: 'aqua',
},
};
...
return (
<ThemeProvider theme={theme}>
...
Run Code Online (Sandbox Code Playgroud)
const StyledButton = styled.a`
${({ theme }) =>
`background-color: ${theme.colors.accentColor};`
}`;
Run Code Online (Sandbox Code Playgroud)
import '@emotion/react';
declare module '@emotion/react' {
export interface Theme {
colors: {
primaryColor: string;
accentColor: string;
};
}
}
Run Code Online (Sandbox Code Playgroud)
src …Run Code Online (Sandbox Code Playgroud) 我是新手,我不明白为什么h1 标签内的标题会更新,但图像组件内的url没有?
import React, { useState, useEffect, useContext } from 'react';
import Image from './Image';
import Size from '../index';
export default function Listing(props) {
const [title, setTitle] = useState(props.title);
const [url, setUrl] = useState(props.url);
const value = useContext(Size);
return (
<div>
<Image url={url} size={value.size} />
<h1>{title}</h1>
<form>
<input id='URL' type='text' />
<button
onClick={e => {
e.preventDefault();
setUrl(document.getElementById('URL').value);
setTitle(document.getElementById('URL').value);
}}
>
Submit
</button>
</form>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的猜测是,如果 prop 发生变化,React 不会更新子组件,但是我该如何手动更新呢?
import React from 'react'; …Run Code Online (Sandbox Code Playgroud) 是否有一个选项可以将 svgo 选项传递给 svgr/webpack 加载器?我想删除宽度和高度属性并保留视图框,默认情况下它会删除这些属性。
{
test: /\.svg$/,
use: ['@svgr/webpack'],
options : {
svgo: { // Something like this ?
mergePaths: false,
removeViewbox: false,
removeAttrs: true,
}}
},
Run Code Online (Sandbox Code Playgroud)