weikee94 / react-ts

react with typescript
0 stars 0 forks source link

Types vs Interfaces #2

Open weikee94 opened 3 years ago

weikee94 commented 3 years ago

click here to see more

weikee94 commented 3 years ago

Typing Children

// typing children declare as ReactNode
type BoxProps = {children: React.ReactNode, style?: React.CSSProperties};

const Box = {{ children, style = {}} : BoxProps} => {
    return (
        <section style={{...style}}>
            {children}
        </section>
    )
}

export default function Application() {
    return (
        <Box>
            just string
            <p>lorem</p>
            <Box> 
                <p>lorem</p>
                <span>lorem2</span>
            </Box>
        </Box>
    )
}