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

[Feature Request] Support custom property #323

Open
NE-SmallTown opened this issue Jan 18, 2021 · 1 comment
Open

[Feature Request] Support custom property #323

NE-SmallTown opened this issue Jan 18, 2021 · 1 comment

Comments

@NE-SmallTown
Copy link

NE-SmallTown commented Jan 18, 2021

Introduction

Today, we can't pass custom property to any React Native Component like View, Image. And if we do that, React Native will throw errors.

Details

There are 3 primary situations we need this feature:

  1. We are building a debug tool like React Developer Tools, so we need a custom protocol/property to display/design the interaction/information with the debug tool.

  2. We are commutating/transferring data with the native(Android/iOS) , so we need a way to define and transfer the data on the component instance.

  3. We are traversing the fiber tree and do something like track/report events to the server, so we need a way to get the data.

Discussion points

Like Web/DOM, it provides a way(data-xxx) to define your custom property and React supports that naturally. But in React Native, there is no way like that. I hope we can support it too, thanks.

@gomes42
Copy link

gomes42 commented Jan 16, 2023

You need to create an component clone.

Example extracted from https://github.com/Luffos/rxn-grife/blob/main/src/components/Text.tsx

import React from "react";
import { Text, Constructor, NativeMethods, TextProps } from "react-native";

export interface _TextProps extends TextProps {
  id?: string;
  className?: string;
}

class TextComponent extends React.Component<_TextProps> {}
const _Text = Text as Constructor<NativeMethods> & typeof TextComponent;

export default _Text;

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

2 participants