Giter Site home page Giter Site logo

Comments (4)

bindoon avatar bindoon commented on August 20, 2024
  • defaultValue: only work in the first render
  • value: for you to control the component value, and you should use onChange to modify the value. that's why called under controlled

you can see the detail in https://reactjs.org/docs/forms.html#controlled-components

from next.

youluna avatar youluna commented on August 20, 2024
  1. children v.s. props
  • children for simple use, and it also makes information more intuitive to a human reader(developer)
<Select>
    <Select.Option value="female">female</Select.Option>
    <Select.Option value="male">male</Select.Option>
    <Select.Option value="secrecy">secrecy</Select.Option>
</Select>;
  • props for a large amount of data sources, maybe you get the data from a remote server with a considerable length
<Select dataSource={dataSource}/>
  1. defaultValue v.s. value
    This involves a concept of React controlled-vs-uncontrolled-components
  • When you use value, the component is controlled and you have full control over the components.It won't change value unless you set the value explicitly.
  • When you use defaultValue only, the components is an uncontrolled component. You don't have to care about the data flow inside component.

defaultValue for basic usage and value for advanced usage, see usage demo

from next.

anyexinglu avatar anyexinglu commented on August 20, 2024

@bindoon @youluna

Thank you for your patient replies, to my shame, I didn't make the question clear:

  1. children v.s. props
<Select>
    <Select.Option value="female">female</Select.Option>
    <Select.Option value="male">male</Select.Option>
    <Select.Option value="secrecy">secrecy</Select.Option>
</Select>
// Attention: Tab.Item has title
<Tab>
    <Tab.Item title="Home">Home content</Tab.Item>
    <Tab.Item title="Documentation">Doc content</Tab.Item>
    <Tab.Item title="Help">Help Content</Tab.Item>
</Tab>

vs

<Select
  dataSource={[
    { label: 'female', value: 'female' },
    { label: 'male', value: 'male' },
    { label: 'secrecy', value: 'secrecy' }
  ]}
/>
// Tab's dataSource seems same as Select's (with label & value, without title)
<Tab
  dataSource={[
    { label: 'Home', value: 'Home content' },
    { label: 'Documentation', value: 'Doc content' },
    { label: 'Help', value: 'Help Content' }
  ]}
/>

The second one seems easier to remember for developers, and more testable for fusion authors.

Obviously, the first one also has some supporters, whatever, a component library can teach users how to write code, supports two usages may increase the maintenance and communication cost, I thought it's not necessary.

  1. defaultValue v.s. value
    I've modified the DatePicker example

defaultValue isn't a good design in react? —— by my leader...

image

from next.

anyexinglu avatar anyexinglu commented on August 20, 2024

咦?

from next.

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.