{"id":10919,"date":"2024-07-18T05:40:58","date_gmt":"2024-07-18T05:40:58","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=10919"},"modified":"2024-07-18T05:40:58","modified_gmt":"2024-07-18T05:40:58","slug":"implement-pull-to-refresh-flatlist","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react-native\/implement-pull-to-refresh-flatlist","title":{"rendered":"Implement Pull to Refresh FlatList"},"content":{"rendered":"<p>React Native provides a built-in RefreshControl component specifically for adding pull-to-refresh functionality to ScrollView and FlatList. Here&#8217;s how to use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\">import React, { useState } from 'react';\r\nimport { FlatList, RefreshControl } from 'react-native';\r\n\r\nfunction MyFlatList() {\r\n  const [refreshing, setRefreshing] = useState(false);\r\n\r\n  const onRefresh = () =&gt; {\r\n    setRefreshing(true);\r\n    \/\/ fetch data\r\n    \/\/ ...\r\n    setRefreshing(false); \r\n  };\r\n  return (\r\n    &lt;FlatList\r\n      data={yourData}\r\n      renderItem={renderItem}\r\n      refreshControl={\r\n        &lt;RefreshControl refreshing={refreshing} onRefresh={onRefresh} \/&gt;\r\n      }\r\n    \/&gt;\r\n  );\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>React Native provides a built-in RefreshControl component specifically for adding pull-to-refresh functionality to ScrollView and FlatList. Here&#8217;s how to use it: import React, { useState } from &#8216;react&#8217;; import { FlatList, RefreshControl } from &#8216;react-native&#8217;; function MyFlatList() { const [refreshing, setRefreshing] = useState(false); const onRefresh = () =&gt; { setRefreshing(true); \/\/ fetch data \/\/ &#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10920,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-10919","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-native"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10919"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=10919"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10919\/revisions"}],"predecessor-version":[{"id":10921,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/10919\/revisions\/10921"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/10920"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=10919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=10919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=10919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}