2

I am trying to compose text components to use throughout a react native application

it is as follows

import React from 'react';
import { Text, TextProperties, StyleSheet } from 'react-native';
import Colors from '../Colors';

export default (props: TextProperties) => <Text style={styles.text} {...props} />

const styles = StyleSheet.create({
    text: {
        color: Colors.primary,
        fontSize: 24,
        fontWeight: 'bold'
    }
});

In effect I am trying to apply styles in a single location and use it throughout the applicaiton.

my issue is that the typescript compiler is complaining:

 error TS2559: Type '{ children: string; }' has no properties in common with type 'IntrinsicAttributes & TextProperties'.

1 Answer 1

3

I figured out a solution. What I did was.

import React from 'react';
import { Text, TextProperties, StyleSheet } from 'react-native';
import Colors from '../Colors';

export default (props: Props) => <Text style={styles.text} {...props} />

interface Props extends TextProperties {
   children: string;
}
const styles = StyleSheet.create({
    text: {
        color: Colors.primary,
        fontSize: 24,
        fontWeight: 'bold'
    }
});
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.