Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazy Load specific tab with React-Navigation v4

I am using React-Navigation V4 and the question is, Is there any way of lazy load only specific tab like if i have four tabs and i want to load two tabs after initialisation of tabs component and don't want to load other two these two only will load when user activates them. if i use lazy: true in React it'll work work all tabs or either lazy load will be disabled for all or enable for all.

like image 648
Waheed Akhtar Avatar asked Nov 07 '22 10:11

Waheed Akhtar


1 Answers

Unfortunately there is not such a thing in react navigation v4. but if you want to achieve performance you can use other methods to kind of lazy load part of screen.

const TabPage = (props) => {
  const [renderHeavy, setRender] = useState(false)

  useEffect(() => {
      InteractionManager.runAfterInteraction(() => setRender(true))
  }, [])

  return (
      <View style={styles.body}>
          {
              renderHeavy &&
              <HeavyComponent />
          }
          <AnotherComponent />
      </View>
  )
 }
like image 189
TheEhsanSarshar Avatar answered Nov 15 '22 05:11

TheEhsanSarshar