0

I want to use component like this:

<Grid>
 <Grid.Column>
  {/*some content*/}
 </Grid.Column>
</Grid>

Grid.tsx

export interface GridProps extends React.HTMLAttributes<HTMLDivElement> {
}

const Grid: React.SFC<GridProps> =({ children, ...props }) =>
        <div {...props}>
            {children}
        </div>

export interface GridColumnProps extends React.HTMLAttributes<HTMLDivElement> {
    size: 1 | 2 | 3 | 4,
    centered?: false
}

const Column: React.SFC<GridColumnProps> = ({ children, ...props }) =>
    <div {...props}>
        {children}
    </div>

Grid.Column = Column; 

At the last line I have an error "Column doesn't exists on type StatelessComponent|GridProps|

1 Answer 1

1

You need to define a custom type for Grid one that is both React.SFC<GridColumnProps> and has a property named Column

type GridType = React.SFC<GridProps> & { Column: React.SFC<GridColumnProps> } 
const Grid: GridType =(({ children, ...props }) =>
        <div {...props}>
            {children}
        </div>) as GridType // Use a type assertion as our function does not have the Column Property yet

Grid.Column = Column; 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.