3

I want to pass props color to a icon child. This <Feather /> I want to add color as props

This is my component and the Feather child

import { Feather } from '@expo/vector-icons'

export default class CloseButton extends React.PureComponent {
  render () {
    const { style, ...props } = this.props
    return (
      <TouchableOpacity style={styles.close} link {...props} >
        <Feather name='x' size={26} /> // <-- want add color here
      </TouchableOpacity>
    )
  }
}

This is my component where I send props thas show in ThouchableOpacity

<Alert.CloseButton onPress={props.onRequestClose} />

How can pass color in this props and it only show on icon?

0

1 Answer 1

1

You could use a prop called color for your CloseButton component that you pass to the Feather component.

export default class CloseButton extends React.PureComponent {
  render () {
    const { style, color, ...props } = this.props;

    return (
      <TouchableOpacity style={styles.close} link {...props} >
        <Feather name='x' size={26} color={color} />
      </TouchableOpacity>
    )
  }
}

Usage

<Alert.CloseButton
  onPress={props.onRequestClose}
  color="red"
/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.