Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧐[问题] ProForm 的 params 与 request 配合使用未根据返回内容刷新表单 #8375

Open
BuknSS opened this issue Apr 30, 2024 · 2 comments

Comments

@BuknSS
Copy link

BuknSS commented Apr 30, 2024

🧐 问题描述

ProForm 的 params 与 request 配合使用未按返回内容重新更新表单字段。

20240430154110_rec_-convert

代码:

import { ProForm, ProFormText } from '@ant-design/pro-components';

export default function TestBug({ id }: { id: number }) {
  async function getById() {
    const data = { content: `id:${id} now:${Date.now()}` };
    console.log('TestBug: getById returns', data);
    return data;
  }
  return (
    <ProForm params={{ id }} request={getById}>
      <ProFormText name="content" label="数据" />
    </ProForm>
  );
}

只要相同 id 出现过,会调用 request,但不会刷新表单字段。

const [id, setId] = useState(0);
setId((id) => id + 1);
setId((id) => id - 1);

<TestBug id={id} />

完整代码:
https://stackblitz.com/edit/vitejs-vite-gfgb6m?file=src%2FApp.tsx

@fnoopv
Copy link
Contributor

fnoopv commented May 9, 2024

request 是用来设置表单默认值的, 当然不会更新表单值, 和 initialValues 作用相同, 不同之处在于 1. 优先级更高, 会覆盖 initialValues 2. 可以请求远程数据。 你用错场景了

@zhoukai12
Copy link

有解决么 我也碰到这个问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants