小编Gau*_*rav的帖子

使用 Formik 进行 React-select 不更新选择字段而是执行其他所有操作

React-Select with Formik 没有在 select 组件中加载选定的值,但我能够获取表单提交和验证的值也适用于 Yup

这是相同的代码和框演示 - https://codesandbox.io/s/wild-violet-fr9re

https://codesandbox.io/embed/wild-violet-fr9re?fontsize=14

import React, { Component } from "react";
import { Formik, Form, ErrorMessage } from "formik";
import * as Yup from "yup";
import Select from "react-select";

const debug = true;

class SelectForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      stateList: [],
      stateCity: "",
      selectedState: "",
      citiesToLoad: []
    };
  }

  handleState(opt) {
    console.log(opt.value);
    let citiesList = [];
    Object.keys(this.state.stateCity).forEach(key => {
      if (key === opt.value) {
        this.state.stateCity[key].map((cityName, j) => { …
Run Code Online (Sandbox Code Playgroud)

reactjs react-select yup formik

6
推荐指数
1
解决办法
9142
查看次数

标签 统计

formik ×1

react-select ×1

reactjs ×1

yup ×1