Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added country selector component #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kirustar14
Copy link

Tracking Info

Resolves #<45>

Changes

I added a country selector component using the react-select and react-select-country-list libraries.

Testing

I put the country selector on the page.tsx and tested to see if it showed up.

Confirmation of Change

Screenshot 2025-02-05 at 11 37 51 AM

@kirustar14 kirustar14 requested a review from Miyuki-L as a code owner February 5, 2025 19:45
@kirustar14 kirustar14 linked an issue Feb 5, 2025 that may be closed by this pull request
Copy link
Member

@Miyuki-L Miyuki-L left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Work.

Just a few changes to add more controll and changability to the component to match the needs of the design.

Also address the linter errors

label: string;
};

export const CountrySelector: React.FC = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have this taking in the p[ace holder text as a prop since place holder text changes depending on design

};

export const CountrySelector: React.FC = () => {
const [value, setValue] = useState<CountryOption | null>(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state should be controled outside the component

i.e. we pass in the value and the set function this way we know the values when we use the component in the form

Something similar to this

import Select from "react-select";
import countryList from "react-select-country-list";

const CountrySelector = ({ value, onChange }) => {
  const options = useMemo(() => countryList().getData(), []);

  return (
    <Select
      options={options}
      value={options.find((option) => option.value === value)}
      onChange={(selected) => onChange(selected?.value)} // Pass value to parent
      isSearchable
    />
  );
};

export default CountrySelector;```

If you want to learn more its controlled vs uncontrolled components https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components


return (
<div>
<Select
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now the element size changes depending on the content. We need to be able to control its width so that we can match it to the design

Two option:

  1. pass in a width prop which is then used to style the comopnent
  2. Find a way so it takes the full width of the parent component i.e. <div> <CountrySelector/> </div> so that the element size will change depending on the size of div.

}
}, []);

const changeHandler = (selectedOption: SingleValue<CountryOption>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap this in a use Callback

image
This error is showing up

I did something like this and it went away since every rerender its creating this function which we also don't really want to do that we
const changeHandler = useCallback( (selectedOption: SingleValue<CountryOption>) => { setValue(selectedOption ?? null); }, [setValue] );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Country Selector
2 participants