Answer the question
In order to leave comments, you need to log in
How to pass props and children to a component in react typescript?
There is a component
import React from 'react';
import BackButton from 'components/buttons/BackButton';
type PropTypes = {
title: string,
goBackText?: string,
children?: React.ReactElement,
} & typeof defaultProps;
const defaultProps = {
goBackText: '',
children: null,
};
const NamePagesBar = ({
title, goBackText, children,
}:PropTypes) => (
<div className="mx-auto px-4 h-18 flex items-center flex justify-between">
<h1>{title}</h1>
{goBackText && (
<BackButton text={goBackText} className="flex items-baseline text-sm text-blue hover:text-blue-dark underline " />
)}
{children}
</div>
);
NamePagesBar.defaultProps = defaultProps;
export default NamePagesBar;
<NamePagesBar title={title}>
<button>efreasrf</button>
</NamePagesBar>
Answer the question
In order to leave comments, you need to log in
defaultProps is irrelevant in TS
type PropTypes = {
title: string
goBackText?: string
};
const NamePagesBar: React.FC<PropTypes> = ({title, goBackText = ''}) => (<...>);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question