Skip to content

Options values as number type #165

Answered by csandman
lucksp asked this question in Q&A
Discussion options

You must be logged in to vote

This is the expected behavior of the base package react-select as far as I'm aware, but there is an easier way to avoid having to convert your values to strings and back again. If you use the getOptionValue prop on the select and do your .toString() in there, it will not affect the base list of options or the submitted values, only what the select uses internally.

<Select
  getOptionValue={({ value }) => value.toString()}
/>

Here's a complete example:

import React, { useState } from "react";
import { Button, Container, FormControl, FormLabel } from "@chakra-ui/react";
import { Select } from "chakra-react-select";

const options = [
  {
    label: "One",
    value: 1
  },
  {
    label: "Two"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lucksp
Comment options

Answer selected by lucksp
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