I’m using react with react router for the client-side routing.
I have a header, outlet, and footer.
What I want is to give the Outlet a classname so that every component get’s a margin-top.
Is there a way to do this or do I have to make a wrapper component surrounding the Outlet?
Question posted in Javascript
A very good W3school tutorial can be found here.
A very good W3school tutorial can be found here.
2
Answers
The
<Outlet
component of the React Router Dom does not have aclassName
prop. If you want to apply a style to the component that would eventually replace theOutlet
component placeholder, then you should wrap theOutlet
with an HTML element and pass yourclassName
orstyle
prop to the HTML element and subsequently pass in the appropriate class that appliesmargin-top
to it.The
Outlet
component itself is not any component or HTML element that takes aclassName
prop nor is it visually rendered to the screen. It’s effectively an invisible container for nested routes to render theirelement
content in.See Outlet: The only prop available is the
context
prop it can provide.Any UI styling you want applied should be implemented in the layout route component rendering the
Outlet
. Yes, you will need to wrap theOutlet
in something that is styleable.Trivial Example: