Git Product home page Git Product logo

Comments (6)

pointhalo avatar pointhalo commented on June 8, 2024

纯对象是什么……看不懂这个描述。
你描述的问题也跟入参是什么格式没有关系的……

from semi-design.

xmsz-stu avatar xmsz-stu commented on June 8, 2024

纯对象是什么……看不懂这个描述。 你描述的问题也跟入参是什么格式没有关系的……

就是非引用对象,现在onChange里拿到的e.values是引用对象,如果其他地方更改了,这里也变化了
实际使用中就导致这个值不是实际表单的值

我现在只能先粗暴的深拷贝一下

from semi-design.

pointhalo avatar pointhalo commented on June 8, 2024

onChange、onValueChange的回调就应该是 read only的,如果你要做write 操作,需要自己clone。

我们不会对这种事件回调的入参做作用域隔离。因为这个操作成本是非常高的,同时它的触发频次会非常高频,且用户无法决定是否触发,如果每次都做 deepClone部分场景这个性能损耗是用户无法承受的。

只有 formApi.getValues、getFormState这种可由用户主动触发的,才会在output 前主动做 deepclpne。
image

from semi-design.

xmsz-stu avatar xmsz-stu commented on June 8, 2024

ok,问个额外的,我现在onChange里拿e.values,主要是为了在Form外部使用useEffect监听form的值。

const [state, setState] = useState();
   useEffect(()=>{
        // STEP: 处理相关的依赖
    },[state])

<Form onChange={(e) => setState(e.values)}></Form>

但是现在每次都要deepclone一次,确实不好,有没有其他方式解决?
我看文档大部分都是子组件获取父Form组件的state

然后其他项目好像都是通过useWatch来解决

from semi-design.

pointhalo avatar pointhalo commented on June 8, 2024
  1. 为什么要额外再用一个 useEffect,不能直接监听后执行Step原因是什么?
  2. 要不你先看看 onValueChange 和onChange的区别?如果你单纯是希望值变更后做一些操作,似乎你更需要的是onValueChange

from semi-design.

xmsz-stu avatar xmsz-stu commented on June 8, 2024
  1. 为什么要额外再用一个 useEffect,不能直接监听后执行Step原因是什么?
  2. 要不你先看看 onValueChange 和onChange的区别?如果你单纯是希望值变更后做一些操作,似乎你更需要的是onValueChange
  1. useEffect只是举例,form的里面的值影响外部的显隐或者计算,作为依赖值
  2. 用onChange是其他组件库的习惯和偷懒覆盖全部状态

from semi-design.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.