Created
November 9, 2023 13:49
-
-
Save yinkakun/8c2a1936553abb3b64e247b986a056c2 to your computer and use it in GitHub Desktop.
Render a component from component object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
type Steps = "component-a" | "component-b" | "component-c"; | |
const ComponentA = () => { | |
return <div>Component B</div>; | |
}; | |
const ComponentB = () => { | |
return <div>Component B</div>; | |
}; | |
const ComponentC = () => { | |
return <div>Component C</div>; | |
}; | |
const STEPS: Record<Steps, React.FC> = { | |
"component-a": ComponentA, | |
"component-b": ComponentB, | |
"component-c": ComponentC, | |
}; | |
const Form = () => { | |
const currentStep = "component-a"; // state might be from url search param | |
const CurrentStep = STEPS[currentStep]; | |
return <CurrentStep />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment