My project involves Webpack, Typescript, and React Hooks with CSS-in-js for styling a div. I encountered an error while hovering over the style
prop in the Menu
component. I'm unsure about where to bind the CSSProperties.
(JSX attribute) React.HTMLAttributes<HTMLDivElement>.style?: React.CSSProperties
Type '{ display: string; margin: number; padding: number; alignItems: string; flexDirection: string; justifyContent: string; width: string; height: string; background: string; }' is not assignable to type 'CSSProperties'.
Types of property 'flexDirection' are incompatible.
Type 'string' is not assignable to type 'FlexDirection'.ts(2322)
index.d.ts(1768, 9): The expected type comes from property 'style' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'
Menu Component:
import React from 'react';
const Menu = () => (
<div maxWidth="lg" style={styles.menuContainer}>
MENU COMPONENT
</div>
)
export default Menu;
const styles = {
menuContainer: {
display: 'flex',
margin: 0,
padding: 0,
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-around',
width: '100%',
height: '5vh',
background: 'rgba(212, 15, 24,0.8)',
}
};
tsconfig.json:
{
"compilerOptions": {
"outDir": "./public",
"noImplicitAny": true,
"module": "AMD",
"target": "es6",
"jsx": "react",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": [ "src", "image.d.ts" ],
"exclude": [ "node_modules", "**/*.spec.ts" ]
}