Unable to render Store URL again

pavan agrawal January 27, 2024

Hello Team,

I have created a Admin Page to store URL. When URL submitted then it render as Submitted URL. However, when we refresh page then saved URL not visible. I want to display URL it is save on the Storage API. how to do that. 

Code - 


const App = () => {
  const [formData, setFormData] = useState({ URL: '' });

  const onSubmit = async (formData) => {
      try {
        await storage.set('BASE_EXTERNAL_API_URL', formData.URL);
        const storedUrl = await storage.get('BASE_EXTERNAL_API_URL');
        setFormData({ URL: storedUrl });
      } catch (error) {
        console.error('Error handling form submission:', error);
      }
    };
  return (
    <Fragment>
      <Form onSubmit={onSubmit}>
        <TextField label="URL" name="URL" value={formData.URL} onChange={(value) => setFormData({ URL: value })} />
      </Form>
      {/* Display the stored URL */}
      {formData.URL && <Text>Stored URL: {formData.URL}</Text>}
    </Fragment>
  );
};

export const renderAdminPage = render(
  <AdminPage>
    <Fragment>
      <App />
    </Fragment>
  </AdminPage>
);

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events