Skip to content

Commit

Permalink
Merge pull request JedWatson#4048 from manprajapat/patch-1
Browse files Browse the repository at this point in the history
Update README.md with React Hooks Example.
  • Loading branch information
JedWatson authored Aug 27, 2020
2 parents 397e953 + 1491575 commit 4fb2fd6
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ yarn add react-select
```

Then use it in your app:

#### With React Component
```js
import React from 'react';
import Select from 'react-select';
Expand Down Expand Up @@ -71,6 +71,32 @@ class App extends React.Component {
}
```

#### With React Hooks
```js
import React, { useState } from "react";
import Select from "react-select";

const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' },
];

export default function App() {
const [selectedOption, setSelectedOption] = useState(null);

return (
<div className="App">
<Select
defaultValue={selectedOption}
onChange={setSelectedOption}
options={options}
/>
</div>
);
}
```

## Props

Common props you may want to specify include:
Expand Down

0 comments on commit 4fb2fd6

Please sign in to comment.