I am new to Typescript. I need to get the child state values to the parent using ref on a button click to update the reducer values.
I have tried passing a ref
to the child but I am getting errors similar to this:
Type '{ value: string; onChange: Dispatch<SetStateAction>; ref: MutableRefObject<HTMLInputElement | undefined>; }' is not assignable to type 'IntrinsicAttributes & Props & { children?: ReactNode; }'.
Property 'ref' does not exist on type 'IntrinsicAttributes & Props & { children?: ReactNode; }'.ts(2322)
parent component
import React, from "react";
import styled from "styled-components";
import {
Page,
Welcome,
ErrorBoundary
} from "components";
const ParentDiv = styled.div`
margin: 0 410px 30px 15px;
`;
export const CreateEvent = (props: any) => {
return (
<Page title='Dashboard'>
<ErrorBoundary>
{(() => {
switch (activeEventStage?.step) {
case 1:
return (
<ErrorBoundary>
<Welcome />
</ErrorBoundary>
);
default:
return null;
}
})()}
</ErrorBoundary>
</Page>
);
};
export default withRouter(CreateEvent);
child component
import React, { useState } from "react";
import { Row, Col } from "react-bootstrap";
export const Welcome = () => {
const { t } = useTranslation();
const [state, setState] = useState({
welBannerTagline: "",
welHeroTitle: "",
});
return (
<CreateEventFormContainer
title={t("event.create.title")}
subTitile={t("welcome.subTitle")}
>
<>
<Row>
<Col lg='6'>
<DropZoneInputField
titleName={t("welcome.bgImage.title")}
onSelectedFiles={onDropFiles}
imageType='bgImage'
value={state.welBgFilename}
/>
</Col>
<Col lg='6'>
<DropZoneInputField
titleName={t("welcome.banner.title")}
onSelectedFiles={onDropFiles}
imageType='bannerImage'
value={state.welBannerFilname}
/>
</Col>
</Row>
</>
</CreateEventFormContainer>
);
};
export default Welcome;