Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent ActionSheet children recreate? #366

Open
chengfengfengwang opened this issue Jun 2, 2024 · 0 comments
Open

How to prevent ActionSheet children recreate? #366

chengfengfengwang opened this issue Jun 2, 2024 · 0 comments

Comments

@chengfengfengwang
Copy link

import ActionSheet from "react-native-actions-sheet";
import { useEffect, useRef, memo } from "react";
import { Text, Button, View } from "react-native";
import type { ActionSheetRef } from "react-native-actions-sheet";
let renderCount = 0;
const Inner = memo(function () {
  useEffect(() => {
    renderCount++
  }, []);
  return (
    <View style={{padding: 20}}>
      <Text>{renderCount}</Text>
      <Text>Hi, I am here.</Text>
      <Text>Hi, I am here.</Text>
      <Text>Hi, I am here.</Text>
      <Text>Hi, I am here.</Text>
      <Text>Hi, I am here.</Text>
    </View>
  );
});
export default function App() {
  const actionSheetRef = useRef<ActionSheetRef>(null);

  return (
    <>
      <Button title="show" onPress={() => actionSheetRef.current.show()} />
      <ActionSheet ref={actionSheetRef}>
        <Inner />
      </ActionSheet>
    </>
  );
}

I want to render a webview within an ActionSheet, similar to the example provided. However, every time the inner component is recreated, it performs poorly in terms of performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant