JSX Whispers
As of LDK v3.10.0, you no longer need to install React and React-related dependencies to use JSX Whispers.
JSX Whispers
JSX is a syntax extension of JavaScript introduced by the team that created React. For the purposes of Whispers, there are a few things we leverage.
Properties can be defined more like an HTML tag, where components look something like
<oh-component propertyOne="x" propertyTwo="y" />
React state is used to propagate changes to the different components, meaning that you don't have to explicitly use the
update()
function of the Whisper object.
Using JSX Whispers is a great way to have an easier time with handling updates in whispers.
The entry point for this webpack config is index.tsx
. You may need to update your build command (or this code) in order to compile properly.
And with that in place, you're ready to try them out! Let's create a simple form that has a text input that we validate the value of. Using JSX, it would look something like this:
In the below code, the ReactWhisper
object is used to render the JSX Whisper. Your Loop will have errors at runtime if you attempt to use it without either importing and using an aptitude or importing the LDK package as shown below.
This will display a Whisper that looks like this:
If we didn't put the word 'valid' in the Whisper, and then we press the 'Validate' button, the Whisper would now look like this:
Demonstrating that the updates we wanted to make to our Whisper are occurring, with much cleaner code than the prior examples. But, you aren't limited to just using JSX Whispers to only when you need to leverage Whisper updates! They can be used to display static content as well.
Last updated