Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-refresh-screen-hook

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-refresh-screen-hook

A simple hook used to refresh an entire screen or re-run some side effects (inside of useEffect)

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Use Refresh Screen Hook

A simple hook used to refresh an entire screen or re-run some side effects (inside of useEffect)

Installation

yarn add react-native-refresh-screen-hook

Motivation

React native does not provide a default way of refreshing entire screens like the browser, so some times a user might take an action an delete an item from the view, so the view should be refreshed or we should fetch the data from the API again.

Usage

import useRefreshHook from 'react-native-refresh-screen-hook';


const HomeScreen = () =>{
    const [todoListRefreshState, refreshTodoList] = useRefreshHook();
    const [todoList, setTodoList] = useState([]);

    useEffect (() =>{
        // fetch todo list
        setTodoList(data);

        // Add the todo list refresh as a use effect dependency
    },[todoListRefreshState])

    return (
        <View>
            <View>
              {
                todoList.map(list =>{
                    <View>
                       // List data here
                    <TouchableOpacity onPress={() =>
                    {
                      deleteItem(list.id)
                      .then(()=>{
                        // Call the refresh function to re run the related side effect
                        refresh()
                      })
                    }}>
                        <Text>Delete</Text>
                    </TouchableOpacity>
                    </View>
                })
              }
            </View>
        </View>
    )

Notes

  • You can call the hook once and get a state that can be passed to all your hooks as a dependency, which effectively means you are refreshing the entire screen.
  • You can call the hook more than once, and have some hooks dependant on the first refresh state and other hooks dependant on another refresh state and so no.

Keywords

FAQs

Package last updated on 29 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc