I want to avoid creating a named component when rendering a child component of a parent. That is, I have the working code below where the dataValueFromContext is returned from InsideComponent and rendered correctly from MyList component (MyContext is available higher in the component tree).
const InsideComponent = () => {
const { dataValueFromContext } = useContext(MyContext);
return (
<span>
value: {dataValueFromContext}
</span>
);
};
export default function MyList() {
return (
<div>
<InsideComponent />
</div>
);
}
The problem is that when I want to remove InsideComponent as a named component and nest it anonymously. Something like what I have below, the code does not even compile. I'm basically trying to avoid creating a named function as well as needing a defined function at the top. For me, this makes readability easier.
export default function MyList() {
return (
<div>
{
() => {
const { dataValueFromContext } = useContext(MyContext);
return (
<span>
value: {dataValueFromContext}
</span>
)
}
</div>
);
}