Plugin - How retrieve data from api for show input

Hello Guys,

I building an plugin but i with problem for retrieve data from apiRequest for show in input called apiKey, the field apiKey return undefined. The code below:

File: /src/client/index.tsx

...
      useEffect(() => {

        const fetchData = async () => {
          const { data } = await this.app.apiClient.request({ url: 'ProvideConfig:get', params: { filterByTk: 1 } });
          setApiKey(data.api_key);
        };
        fetchData();
      }, [])

        const itemsTabs: TabsProps['items'] = [
          {
            key: '1',
            label: 'Messages',
            children: (<Table dataSource={dataSource} columns={columns} />),
          },
          {
            key: '2',
            label: 'Configuration',
            children: (<>
              <p><Alert message={instructions} type="error" /></p>
              <Form layout="vertical">
                <Form.Item label="* API Key:" style={{ fontWeight: 'bold' }}>
                  <Input placeholder="xxxxxxxxxx" value={apiKey}/>
                </Form.Item>
....

Please refer to https://client.docs.nocobase.com/core/request#userequest

1 Like