Quantcast
Viewing all articles
Browse latest Browse all 6402

When creating a reusable component in React, how do I pass all other props to be accessible later when the component is being used?

I'm creating some custom components for my application and they essentially have some base styling done to them for light/dark modes. My goal is to be able to use those components with all their props later when the custom component is being used to stay flexible. How do I achieve this?

For example if I style a custom input component and use it, I want to be able to tap into the secureTextEntry prop when needed. Here is an example of what I have right now for my CustomText. I want to be able to style this further when needed.

import { Text, useColorScheme } from 'react-native';import React from 'react';type CustomTextProps = {  text: string;};const CustomText = ({ text }: CustomTextProps) => {  const isDarkMode = useColorScheme() === 'dark';  return <Text style={{ color: isDarkMode ? '#fff' : '#000' }}>{text}</Text>;};export default CustomText;

Viewing all articles
Browse latest Browse all 6402

Trending Articles