Below is my source code
EDTIComp.tsx
function SentenceBuild(props: {
form: FormHook
fieldPath: EditMedicationForm.InstructionFields;
defaultValue: string;
useDefaultValue: boolean;
readOnly?: boolean;
}) {
const startsOn = moment(instruction.startsOn, ValidDateFormats.NodeDateTimeTimezone);
let showStartsOn = false;
if (startsOn && startsOn.isValid()) {
showStartsOn = moment().endOf('day').isBefore(startsOn, 'day');
return (
{showStartsOn && (
prefix='starting on' readOnly={props.readOnly} value={moment(startsOn).format(ValidDateFormats.Edit)} default='[date]' /> )}
);
}
EDSF.tsx
const performedOnMoment = Here I want to showStartsOn value

Naimish MakwanaRank #324 · 7.7K reputationPosted Dec 28, 2024, 7:44 AM EST
To pass the
showStartsOnvalue from theSentenceBuildcomponent to the parent component (EDSF.tsx), you can use a callback function. Here's how you can modify your code:EDSF.tsx) to receive theshowStartsOnvalue.SentenceBuildcomponent.SentenceBuildcomponent to pass theshowStartsOnvalue.Here's an example:
EDSF.tsximport React, { useState } from 'react'; import SentenceBuild from './EDTIComp'; const EDSF = () => { const [performedOnMoment, setPerformedOnMoment] = useState(false); const handleShowStartsOn = (value: boolean) => { setPerformedOnMoment(value); }; return ( Performed On Moment: {performedOnMoment ? 'True' : 'False'} ); }; export default EDSF;import React from 'react'; import moment from 'moment'; function SentenceBuild(props: { form: FormHook; fieldPath: EditMedicationForm.InstructionFields; defaultValue: string; useDefaultValue: boolean; readOnly?: boolean; onShowStartsOnChange: (value: boolean) => void; }) { const startsOn = moment(instruction.startsOn, ValidDateFormats.NodeDateTimeTimezone); let showStartsOn = false; if (startsOn && startsOn.isValid()) { showStartsOn = moment().endOf('day').isBefore(startsOn, 'day'); } // Invoke the callback function to pass the showStartsOn value to the parent props.onShowStartsOnChange(showStartsOn); return ( {showStartsOn && ( )} ); } export default SentenceBuild;In this example:
EDSFcomponent defines a state variableperformedOnMomentand a callback functionhandleShowStartsOn.SentenceBuildcomponent receives the callback function as a prop (onShowStartsOnChange) and invokes it with theshowStartsOnvalue.This way, the
showStartsOnvalue is passed from the child component (SentenceBuild) to the parent component (EDSF).Thanks
amar Praveen31 reputationPosted Dec 29, 2024, 6:04 AM EST
amar Praveen31 reputationPosted Jan 2, 2025, 7:23 AM EST
Same steps I have followes but no luck.
Can you please let us know if anything need to change