Skip to content

add DidUpdate support to typeahead #148

Description

@WpSlt

I would like to propose to add DidUpdate support to your typeahead field.
Somenthing like it:

function isValidOptions(options) {
  return !!options && options.constructor === Array;
}

export class AsyncTypeaheadField extends BaseTypeaheadField {
  constructor(props) {
    super(props);

    let { schema, uiSchema: { asyncTypeahead }, formData } = this.props;

    this.state = {
      options: isValidOptions(asyncTypeahead.options) ? asyncTypeahead.options : [],
      isLoading: false,
      selected: isValidFormData(formData)
        ? toSelected(formData, schema, asyncTypeahead.mapping, asyncTypeahead.options)
        : [],
    };
  }

	componentDidUpdate(prevProps, prevState) {
	  if (this.props.uiSchema !== prevProps.uiSchema) {
		let { schema, uiSchema: { asyncTypeahead }, formData} = this.props;

		this.setState({
		  options: isValidOptions(asyncTypeahead.options) ? asyncTypeahead.options : [],
		  isLoading: false,
		  selected: isValidFormData(formData)
			? toSelected(formData, schema, asyncTypeahead.mapping, asyncTypeahead.options)
			: [],
		});
	  }
	}
....

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions