I am having difficulties understanding how to build a rather simple component that has a variety of props that need to be accessed inside a nested component, within. I don't even know if that is how to correctly explain my situation, regardless I feel like this should be simple.
I'll explain. I have a component as follows:
<Widget
layout="small"
header="This is the header"
icon={<UploadIcon/>}
title="This is the title"
caption="This is the caption to a widget it should have a character count"
to="/tosomwhere"
href="http://www.website.com"
link="Link Title"
/>
And the component code.
const Widget = (props) => {
return (
<WidgetWrapper layout={props.layout}>
hello world
{props.title}
</WidgetWrapper>
);
}
Widget.propTypes = {
layout: PropTypes.oneOf(['small', 'large', 'dual']),
header: PropTypes.string,
icon: PropTypes.element,
title: PropTypes.string,
caption: PropTypes.string,
to: PropTypes.string,
href: PropTypes.string,
link: PropTypes.string,
};
Widget.defaultProps = {
layout: 'small'
};
export default Widget;
As you can see I am including a component inside the component. It's purpose is purely visual (size of widget, color, ext), but it needs to wrap all the props coming from
I can access props.layout as it's outside the component, but I can't access props.title inside that belongs to .
How is this done? Do I need to pass props down through so I can access them that way? I tried to add a props={props} to with no success...
WidgetWrapper, you can use<WidgetWrapper {...props} />