就应用程序启动而言,我采取了一种稍微不同的方法,因为我想在App
组件中使用useLocation
挂钩。我对打字有点陌生,遇到了一个问题。这是我的:
// index.tsx
const theme: Theme = createMuiTheme({
palette: {
primary: {
main: '#43C099',
},
},
});
ReactDOM.render(
<Provider store={store}>
<ThemeProvider theme={theme}>
<CssBaseline />
<Router>
<App theme={theme} />
</Router>
</ThemeProvider>
</Provider>
, document.getElementById('root'));
// App.tsx
interface IFC extends FC {
theme: Theme
}
const App: FC<IFC> = ({ theme }) => {
// ...
错误来自index.tsx
,IDE在<App ...
下加下划线并抛出错误
Type '{ theme: Theme; }' is not assignable to type 'IFC'.
我在这里做错了什么?
想明白了。应该是
interface IFC {
theme: Theme
}