I want to show the text I pass into the parameter.
export default function Paragraph(text) {
return(
<div>
{text}
</div>
)
}
But so far it doesn’t render the text. I have even tried calling it as such
<Paragraph text="Some text"></Paragraph>
2
Answers
The Paragraph component should receive a "props" object argument, and the value of the "text" key should be obtained by destructuring the props object.
Components receive an object called props as sole argument and we use it to access all the properties passed to the component.
Solid need function calls to preserve reactivity. Since props object uses a getter internally, reactivity is preserved. However when you destructure the props object, you will be opting out of reactivity.
So, here is how you define the said component with types and all:
If you don’t use typescript: