
ReactiveList creates a data-driven result list UI component. This list can reactively update itself based on changes in other components or changes in the database itself.
Example uses:
- showing a feed of results based on the applied search criteria.
Usage
Basic Usage
<ReactiveList
react={{
and: ['CitySensor', 'SearchSensor'],
}}
onData={res => <Text>{res.title}</Text>}
/>Usage With All Props
<ReactiveList
componentId="SearchResult"
dataField="ratings"
pagination={false}
paginationAt="bottom"
pages={5}
sortBy="desc"
size={10}
showResultStats={true}
onData={res => <Text>{res.title}</Text>}
onResultStats={(total, took) => {
return 'found ' + total + ' results in ' + took + 'ms.';
}}
react={{
and: ['CitySensor', 'SearchSensor'],
}}
/>Props
- componentId
Stringunique identifier of the component, can be referenced in other components'reactprop. - dataField
Stringdata field to be connected to the component's UI view. It is useful for providing a sorting context. - pagination
Boolean[optional] pagination <> infinite scroll switcher. Defaults tofalse, i.e. an infinite scroll based view. When set totrue, a pagination based list view with page numbers will appear. - paginationAt
String[optional] Determines the position where to show the pagination, only applicable when pagination prop is set totrue. Accepts one oftop,bottomorbothas valid values. Defaults tobottom. - pages
Number[optional] number of user selectable pages to be displayed when pagination is enabled. Defaults to 5. - sortBy
String[optional] sort the results by eitherascordescorder. It is an alternative tosortOptions, both can't be used together. - size
Number[optional] number of results to show per view. Defaults to 10. - showResultStats
Boolean[optional] whether to show result stats in the form of results found and time taken. Defaults totrue. - onResultStats
Function[optional] show custom result stats using a function that takes two parameters fortime_takenandtotal_resultsand returns a string. - react
Object[optional] a dependency object defining how this component should react based on the state changes in the sensor components. - onData
Function[optional] returns a list element object to be rendered based on theresdata object. This callback function prop is called for each data item rendered in the ReactiveList component's view. For example,onData = { function(res) { return ( <View> <Text>{res.tilte}</Text> <Text>{res.description}</Text> </View> ); }, }; - onAllData
Function[optional] works like onData prop but all the data objects are passed to the callback function. - innerProps
Object[optional] specifies additional props for the internal components. Accepts an object with the specified keys. Read more about the usage here
Key |
Explanation |
|---|---|
icon |
Icon component from native-base |
button |
Button component from native-base |
spinner |
Spinner component from native-base |
text |
Text component from react-native |
Demo
Try the demo instantly.
Styles
ReactiveList component supports style prop. Read more about it here.
It also supports an innerStyle prop with the following keys:
labelbuttonicon
Read more about it here
Extending
ReactiveList component can be extended to
- customize the look and feel with
style, - render individual result data items using
onData, - render the entire result data using
onAllData.
<ReactiveList
...
style={{ paddingBottom: 10 }}
onData={(res) => <Text>{res.data}</Text>}
/>- style
ObjectCSS styles to be applied to the ReactiveList component. - onData
Function[optional] a callback function where user can define how to render the view based on the data changes. - onAllData
Function[optional] an alternative callback function toonData, where user can define how to render the view based on all the data changes. It accepts two parameters,results, and a callback function which should be called when the results reach the end (on scroll).
onAllData(results, loadMoreData) {
// return the list to render
}