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

chore: added basic usage code to README.md #709

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

## Screenshots

<p float="left">

Check failure on line 12 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Inline HTML [Element: p]
<img src="https://user-images.githubusercontent.com/56504893/116790110-e0b36880-aac7-11eb-9ebd-196acee64f7a.png"

Check failure on line 13 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Inline HTML [Element: img]
width="270" alt="Screenshot showing basic dropdown" />
<img src="https://user-images.githubusercontent.com/56504893/116789802-faec4700-aac5-11eb-837b-86f18cbfcf3d.png"

Check failure on line 15 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Inline HTML [Element: img]
width="270" alt="Screenshot showing badges" />
<img src="https://user-images.githubusercontent.com/56504893/116789839-2c651280-aac6-11eb-99e0-b43b608ed8c7.png"

Check failure on line 17 in README.md

View workflow job for this annotation

GitHub Actions / Lint Markdown files

Inline HTML [Element: img]
width="270" alt="Screenshot showing dark theme and parent items" />
</p>

Expand All @@ -23,10 +23,64 @@

## Usage

You can find runnable examples in the `examples` subdirectory, which is a
working [Expo](https://github.com/expo/expo) project demonstrating this library.
Navigate into the `examples` subdirectory, run `npm install`, and then run
`npx expo start` to see the examples working.
### Basic usage

The following code shows basic usage of the library:

```javascript
import React, {useState} from 'react';
import {View, Text} from 'react-native';
import DropDownPicker from 'react-native-dropdown-picker';

export default function App() {
const [open, setOpen] = useState(false);
const [value, setValue] = useState(null);
const [items, setItems] = useState([
{label: 'Apple', value: 'apple'},
{label: 'Banana', value: 'banana'},
{label: 'Pear', value: 'pear'},
]);

return (
<View style={{flex: 1}}>
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 15,
}}>
<DropDownPicker
open={open}
value={value}
items={items}
setOpen={setOpen}
setValue={setValue}
setItems={setItems}
placeholder={'Choose a fruit.'}
/>
</View>

<View style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}}>
<Text>Chosen fruit: {value === null ? 'none' : value}</Text>
</View>
</View>
);
}
```

### Further information on usage

You can find more examples in the `examples` subdirectory. This subdirectory is
a working [Expo](https://github.com/expo/expo) project demonstrating this
library. It shows how to use the library with class components as well as
function components, and in TypeScript as well as in JavaScript. Navigate into
the `examples` subdirectory, run `npm install`, and then run `npx expo start` to
see the examples working.

For further information on how to use this library,
read [the relevant documentation](https://hossein-zare.github.io/react-native-dropdown-picker-website/docs/usage).
Expand Down
Loading
Loading