공부방
Style Props 본문
Style Props 주는 법
Container.tsx
type ContainerProps = {
styles: React.CSSProperties;
// 스타일의 타입
};
export const Container = (props: ContainerProps) => {
return <div style={props.styles}>내용이 여기 들어옴</div>;
};
App.tsx
import "./App.css";
import { Container } from "./components/Container";
function App() {
return (
<div className="App">
<Container styles={{ border: "1px solid black", padding: "1rem" }} />
</div>
);
}
export default App;
'TypeScript+React' 카테고리의 다른 글
useReducer (0) | 2023.09.03 |
---|---|
useState (0) | 2023.08.31 |
Event Props (0) | 2023.08.30 |
props 여러 타입들 (0) | 2023.08.30 |
타입스크립트 리액트 기본 (0) | 2023.08.30 |