Mapping an array
Last updated
Last updated
Dynamically rendering content is crucial for building interactive UIs. JSX.Design simplifies this process, enabling you to map arrays to components like lists, tables, or grids. Whether it's rendering a product catalogue or user profiles, JSX.Design makes dynamic rendering seamless.
Design your canvas with a structure to render repeated elements (e.g., a list of items).
For better reusability, consider converting the list item into a custom component. Learn more about custom components.
Choose the parent div
that contains the components to be repeated.
Ensure it has only one nested component inside.
On the Style tab, under Div Options, enable array.map
Set a test count to preview how many items the array should render (e.g., 4).
Specify the array source as a prop, e.g., props.movielist
Go back to your IDE. Inside the canvas-file tag, map the array. For example, let's say your JSX.Design canvas is named 'auth'
For example, you want to link the below array to a list with a title and genre for each list item.
Here's how you can do it:
Select an element inside the list (e.g., the title).
Navigate to the Typography panel, and replace the text with:
Similarly, for another element (e.g., description), use:
While you won’t see the mapped data in the JSX.Design editor, the rendered output will display the data in your React application.
Dynamic Previews: Use the test count feature in JSX.Design to approximate how the final layout will appear.
Custom Components: Always prefix props
when mapping data in custom components to ensure proper binding.
Congratulations! You've mastered the basics. Ready to deep-dive to more advanced features?