0
0
React Nativemobile~20 mins

Pull-to-refresh in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pull-to-refresh Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when you pull down on a ScrollView with RefreshControl?
In React Native, when you add a RefreshControl to a ScrollView, what is the expected behavior when the user pulls down on the list?
React Native
import React, { useState } from 'react';
import { ScrollView, RefreshControl, Text } from 'react-native';

export default function App() {
  const [refreshing, setRefreshing] = useState(false);

  const onRefresh = () => {
    setRefreshing(true);
    setTimeout(() => setRefreshing(false), 2000);
  };

  return (
    <ScrollView
      refreshControl={<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />}
    >
      <Text>Pull down to refresh</Text>
    </ScrollView>
  );
}
AThe list scrolls up and triggers the onRefresh function, showing a spinner until refreshing is true.
BThe list scrolls down and immediately reloads without showing any spinner.
CThe list scrolls down but does not trigger any function or show any spinner.
DThe list scrolls down and triggers the onRefresh function, showing a spinner until refreshing is false.
Attempts:
2 left
💡 Hint
Think about what the RefreshControl component does when refreshing is true.
lifecycle
intermediate
2:00remaining
What is the role of the refreshing state in Pull-to-refresh?
In a React Native pull-to-refresh implementation, why do we need a refreshing state variable?
React Native
const [refreshing, setRefreshing] = useState(false);

const onRefresh = () => {
  setRefreshing(true);
  fetchData().then(() => setRefreshing(false));
};
AIt disables the ScrollView while refreshing is true.
BIt stores the data fetched from the server during refresh.
CIt controls whether the spinner is visible and stops it when data loading finishes.
DIt triggers the onRefresh function automatically when set to true.
Attempts:
2 left
💡 Hint
Think about what the RefreshControl uses to show or hide the loading spinner.
📝 Syntax
advanced
2:30remaining
Which code snippet correctly implements pull-to-refresh in a FlatList?
Select the code snippet that correctly uses RefreshControl with a FlatList to enable pull-to-refresh.
A
import { FlatList, RefreshControl } from 'react-native';

&lt;FlatList
  data={data}
  renderItem={renderItem}
  refreshControl={&lt;RefreshControl refreshing={refreshing} onRefresh={onRefresh} /&gt;}
/&gt;
B
import { FlatList } from 'react-native';

&lt;FlatList
  data={data}
  renderItem={renderItem}
  onRefresh={onRefresh}
  refreshing={refreshing}
/&gt;
C
import { FlatList } from 'react-native';

&lt;FlatList
  data={data}
  renderItem={renderItem}
  refreshControl={RefreshControl(refreshing, onRefresh)}
/&gt;
D
import { FlatList, RefreshControl } from 'react-native';

&lt;FlatList
  data={data}
  renderItem={renderItem}
  refreshControl={&lt;RefreshControl onRefresh={onRefresh} /&gt;}
/&gt;
Attempts:
2 left
💡 Hint
Remember that RefreshControl is a component and must be passed as JSX inside refreshControl prop.
🔧 Debug
advanced
2:30remaining
Why does the spinner never stop after pull-to-refresh?
Given this code snippet, why does the spinner keep spinning forever after pulling to refresh? const [refreshing, setRefreshing] = useState(false); const onRefresh = () => { setRefreshing(true); fetchData(); };
React Native
const [refreshing, setRefreshing] = useState(false);

const onRefresh = () => {
  setRefreshing(true);
  fetchData();
};
ABecause fetchData is synchronous and blocks the UI thread.
BBecause setRefreshing(false) is never called after fetchData finishes, so spinner stays visible.
CBecause setRefreshing(true) should be called after fetchData, not before.
DBecause refreshing state should be initialized as true, not false.
Attempts:
2 left
💡 Hint
Think about when the refreshing state is set back to false.
🧠 Conceptual
expert
3:00remaining
How to ensure accessibility for pull-to-refresh in React Native?
Which approach best improves accessibility for users relying on screen readers when implementing pull-to-refresh in React Native?
AAdd an accessible label to the RefreshControl and announce refresh status changes using accessibilityLiveRegion.
BAdd a button outside the list to manually trigger refresh instead of pull-to-refresh.
CUse only visual spinner without any accessibility props because screen readers ignore RefreshControl.
DDisable pull-to-refresh for screen reader users to avoid confusion.
Attempts:
2 left
💡 Hint
Think about how screen readers get notified about UI changes.