我里面有这个简单的函数app.tsx
来呈现一个表格。标题很好看(黑底白字)。
import React from 'react';
import { Table, Thead, Tbody, Tr, Th, Td } from "@chakra-ui/react"
export default function App() {
return(
<Table variant="simple" size="sm">
<Thead>
<Tr>
<Th>A</Th>
<Th>B</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>a</Td>
<Td>b</Td>
</Tr>
</Tbody>
</Table>
)
}
但是,如果我将文件名改为app.jsx
,则将呈现同一个表,但标题很难看到:
要复制这个:
git clone https://github.com/somguyth/chakra-ui-header-bug.git
cd chakra-ui-header-bug
npm install
npm run dev
然后打开localhost:9000
并更改app.jsx
并app.tsx
观察代码重新编译后标题颜色如何变化。
编辑:我能够通过放入(除了)来“修复<ChakraProvider theme={darkTheme}>
”app.jsx
它index.tsx
。检查标头的元素以查看它为什么被修复,th
标签内的类回到了正确的css-4v3u8n
,而不是不正确的css-r10se1
。我不知道这意味着什么或如何正确修复它(即如何修复它而不必使用ChakraProvider
两次)。
我的index.tsx
:
import React from "react";
import ReactDOM from "react-dom";
import { ChakraProvider, extendTheme } from "@chakra-ui/react"
import App from "./app"
const darkTheme = extendTheme({
config: {
useSystemColorMode: false,
initialColorMode: "dark"
}
});
ReactDOM.render(
<ChakraProvider theme={darkTheme}>
<App />
</ChakraProvider>,
document.getElementById("root")
);
和我的模块规则webpack.config.js
:
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
{
test: /\.m?jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', "@babel/preset-react"]
}
},
resolve: {
fullySpecified: false,
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
],
},
我的.babel.rc
:
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
我的package.json
:
{
"name": "test",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack serve"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@chakra-ui/icons": "^1.0.14",
"@chakra-ui/react": "^1.6.5",
"@emotion/react": "^11.4.0",
"@emotion/styled": "^11.3.0",
"css-loader": "^5.2.7",
"framer-motion": "^4.1.17",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-table": "^7.7.0",
"typescript": "^4.3.5"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/preset-react": "^7.14.5",
"@types/react-dom": "^17.0.9",
"@types/react-table": "^7.7.2",
"babel-loader": "^8.2.2",
"html-webpack-plugin": "^5.3.2",
"ts-loader": "^9.2.3",
"webpack": "^5.45.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
}