Skip to content

Swap two input fields (react-select) #5124

Answered by manjushsh
teifler asked this question in Q&A
Discussion options

You must be logged in to vote

@teifler Something like this?

  const [option, updateOption] = useState(null);
  const [secondOption, updateSecondOption] = useState(null);
  
  const onSwap = () => {
    const tempStore = secondOption;
    updateSecondOption(option);
    updateOption(tempStore);
    // Calulation logic...
  };

Component:

const SimpleSelect = ({
  option,
  updateOption,
  secondOption,
  updateSecondOption,
  onSwap
}) => {
  const options = [
    { value: "121", label: "121" },
    { value: "122", label: "122" },
    { value: "123", label: "123" }
  ];

  return (
    <div className="App">
      <h3>Second React Select</h3>
      <Select
        // menuIsOpen={true}
        value={secondOption}
      …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@teifler
Comment options

@manjushsh
Comment options

@teifler
Comment options

Answer selected by teifler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants