Types of callbacks in a component #186
cruxcode
started this conversation in
Guides: Atri Framework Reference
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When we create a React component that can drag & dropped we have to write a corresponding schema for it. This schema is of type
ReactComponentManifestSchema
as defined here https://github.com/Atri-Labs/atrilabs-engine/blob/main/packages/react-component-manifest-schema/src/types.tsYou will also find a field
ReactComponentManifestSchema.dev.attachCallbacks
in this schema. This field describes the callbacks that the corresponding React component can take. For example, a Button component can takeonClick
.Let's discuss all the callback types one by one:
controlled
Since all the react components are controlled components i.e. most of the inputs come as props and the components rarely have an internal state of their own, these props need to be updated when a user performs an action. For example, you can have a look at Input component. The
onChange
callback is of typecontrolled
and theselector: [["custom", "value"]]
also tells us which field should be updated when theonChange
event handler is called.Below is the excerpt from InputComponent:
file_input
The
file_input
type is the same ascontrolled
except that the value is actually aFileList
object. You can refer toUpload
component to understand this category type.do_nothing
As the name suggests,
do_nothing
type is used when none of the component's props need to be updated when an event occurs. A good example will beonClick
inButton
component. When user clicks a button, we don't need to do anything in the frontend. We might need to just inform the backend that the developer can set viaActions
panel.Beta Was this translation helpful? Give feedback.
All reactions