Creating & using Props
Last updated
Last updated
Props in JSX.Design provide a powerful way to customize and control your React components and canvases. This guide walks you through their creation and usage, including advanced scenarios and integration with your IDE.
Select the component you want to add a prop to.
Navigate to the Props tab in the right sidebar.
Click on the Add button
Give a name for your prop (Eg: onClick) and click on Add Prop
(Optional) Click on the expand button to view more inputs:
Set the prop type: String, number or boolean
Set the value
Typically, you can call props directly using the component name. For example, to call an onClick prop inside a button: <button onClick="value"/>
However, when importing an entire canvas, ensure each prop is uniquely identifiable. Here's how you can do it:
Select the component with the prop.
Navigate to the Props tab in the right sidebar.
On Elem ID input, give a unique ID.
On IDE, access props using the format: componentID_propname
For example, let's say you want to call an onClick prop of a button with elemID submitBtn, which is part of a canvas named 'auth':
JSX.Design supports Ant Design (AntD) props for compatible components:
Select the AntD component.
Use the Props tab to add supported properties (e.g., type="primary"
).
Props can also trigger view states in custom components:
Ensure the custom component has defined view states (e.g., isExpanded
).
Create a prop with the same name as the view state.
Set the prop type to boolean.
When the prop is set to true
, the corresponding view state will be triggered.
For complex scenarios, such as accessing props within a custom component's nested elements:
After ejecting, you can directly manipulate nested elements and their props.
You've mastered Props! Let's move on:
Eject the custom component. Learn more about