Introduction
Integration for React and React-Native
❓ react
The react
package is a set of utilities that simplifies the way AgileTs is integrated into a React environment.
Think of it as an extension of AgileTs in the context of React
that serves as an interface to React Components.
The main task of the react
integration is to bind AgileTs States to React Components.
This ensures that AgileTs will re-render the Component when the bound State changes.
It also provides some other valuable functionalities
that optimize the workflow with AgileTs in a React project.
A distinction is made between Functional
and Class
Components.
As we prefer to use React Hooks
in Functional Components,
however, Hooks aren't supported in Class Components.
Therefore, we have created alternatives for Class Components
in order to offer the most essential functionalities there as well.
🐆 Functional Component
In Functional Components
we recommend using AgileTs Hooks like useAgile()
.
The useAgile()
Hook binds Agile Sub Instances
(like States or Collections) to React Components for reactivity.
// -- MyComponent.jsx ------------------------------------------
// Binds MY_FIRST_STATE to 'MyComponent.jsx' for reactivity
const myFirstState = useAgile(MY_FIRST_STATE);
To find out more about useAgile()
, and other Hooks provided by AgileTs,
checkout the AgileTs Hook documentation.
🦖 Class Component
For Class Components
, we provide the AgileHOC
.
The AgileHOC
is a Higher Order Component that is wrapped around a React Component.
It takes care of binding Agile Sub Instances
(like States or Collections) to the wrapped React Components for reactivity.
// -- MyComponent.jsx ------------------------------------------
// Binds MY_FIRST_STATE to 'MyComponent.jsx' for reactivyty
export default AgileHOC(myComponent, [MY_FIRST_STATE]);
To find out more about the AgileHOC
and how to correctly use AgileTs in Class Components,
take a look at the AgileHOC documentation.