To place a react component onto any Django page:
- Create a top level component in
frontend/portals
- Add that to portals in
frontend/react/PortalLoader.tsx
- Use this Django tag to place a div on the page:
{% react_portal NestYachts %}
Any extra supplied args are passed to the react component as props:
{% react_portal AgentsListings agentId=agentId %}
<div class="no-js-content">
<h2>fallback content</h2>
</div>
{% endreact_portal %}
div
with ".no-js-content" will only be displayed if the browser does not have javascript enabled. It is important for SEO to put content here.
ThePortalLoader
is a webpack bundle which is placed once on the base_site.html. When the page is first loaded it will search for all elements with data-react-portal, lazy load their bundles and activate them.
You can't dynamically add a portal using this system—it is intended for enhancing the Django pages.
You can dynmamically add a portal using standard react from any other part of your application.