Hi everyone, new to JIRA App development here, and am trying to get my app to update the state of a form based on data that is stored via the Forge Storage API.
The data is storing correctly and is being retrieved but the form doesn’t update its state. Here is the code:
The useEffect hook runs when one of the variables in the hook’s second argument, which is the dependency array, changes its value. However, I think you need to use the useAction because it will run when the function runs for the purpose of synchronising the state of the function with external systems such as the Forge storage service.
According to the Forge docs this should work. I’m guessing it’s some kind of bug in their custom React environment. Some ideas to try:
Try setting formData in the useState hook instead of useEffect. This should work according to docs because it can take an async function. const [formData, setFormData] = useState(await storage.get(STORAGE_KEY_PREFIX + 'App_Control')); This seems like the equivalent of what you are trying to accomplish with the useEffect hook. That is, setting the intitial formData state from storage.
Try removing the empty dependency array in useEffect. In this case, I don’t think it’s a necessary optimization since this is rendered on the server. It’s not like client-side react, where each keystroke can trigger a possible re-render.
How do you know the item is in storage? How are you verifying this?
In your case, you would be calling a storage operation asynchronously. Note that you can also call setMyRandomNumber() as the result of something like form handling.