DEV Community

Harimangal Pandey
Harimangal Pandey

Posted on

How to set defaultValue for a select field? After fetching the data

I'm trying to set it using defaultValue props, and it's working but it's showing error in the console. It says it's not the right way to implement default value.
I'm quite stuck with it.

I found this solution on internet, but I'm not able to understand.
Can anyone explain?

{getFieldDecorator(`names[${k}]`, {
        validateTrigger: ["onChange", "onBlur"],
        initialValue: "lucy",
        rules: [
          {
            required: true,
            whitespace: true,
            message: "Please input passenger's name or delete this field."
          }
        ]
      })(
        <Select>
          <Option value="jack">Jack</Option>
          <Option value="lucy">Lucy</Option>
          <Option value="Yiminghe">yiminghe</Option>
        </Select>
      )}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)