State and props
DoksJS components have two main ways to store data: state and props.
State is a powerful way to store data in DoksJS components. It allows you to create components that are more dynamic and interactive. Props are a way to pass data to DoksJS components from their parent components. This can be useful for sharing data between components or for passing data into a component that needs it to function.
State is data that is specific to the component and that can be changed by the component.
Props are data that is passed to the component from its parent component and that cannot be changed by the component.
Here is an example of a DoksJS component that uses state:
This component has a state variable called count
. The count
variable tracks the number of times the button has been clicked. The handleClick()
method is called when the button is clicked and it increments the count
variable. The render()
method renders the component's HTML markup and sets the count
prop to the value of the count
variable.
Here is an example of a DoksJS component that uses props:
This component uses the name
prop to render the name of the user. The name
prop is passed to the component from its parent component.