When developing a front end, there are times when you want to store a user-entered string or a selected value as state and send it to the server as a variable. In such cases, please follow the guide below for implementation.Documentation Index
Fetch the complete documentation index at: https://docs.morph-data.io/llms.txt
Use this file to discover all available pages before exploring further.
Declaring State: defineState()
Use defineState() to declare your state. defineState() takes an object as an argument and sets it as the initial value.
Accessing the State Value: .value
You can access the value of the declared state by calling the .value property as shown below.
Tips
If it’s cumbersome to specify the variable name declared by
If it’s cumbersome to specify the variable name declared by
topPageState. and defineState() every time as in this example, you can shorten it by destructuring the variables.Updating the State: .update()
To update the state, use the update() method.
Using Input Components
In the Morph framework, there are components available for reflecting user input to the state declared withdefineState(). For details, see Input Components. By using these input components, you can easily reflect user input in the state.
Passing Values to Data Components
Data components can accept a property calledvariables. By passing the values of the state declared with defineState() to this property, you can pass user-entered values to Python functions or SQL files.
By combining all the features we have seen so far, you can create a data app like the example below.