Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

JSX element type 'string' is not a constructor function for JSX elements. Typescript

$
0
0

So i have been working on a reusable icon element that I can call in any class and just pass a string <Icon name="chat" /> that contain the specific colour of the icon .. This error is the result of the previous question I raised .. you can find the link below

I raised a question early before this:

icon.ts file

const iconsList = {    heart: '&#xe800;',    star: '&#xe801;',    like: '&#xe800;',    dislike: '&#xe802;',    flash: '&#xe803;',    marker: '&#xf031;',    filter: '&#xf0b0;',    user: '&#xf061;',    circle: '&#xf039;',    hashtag: '&#xf029;',    calendar: '&#xf4c5;',    chevronLeft: '&#xf004;',    optionsV: '&#xf142;',    optionsH: '&#xf141;',    chat: '&#xf4ac;',    explore: '&#xf50d;'};interface Props{    name: keyof typeof iconsList;}const Icon = ({name }: Props) => {    let icon = iconsList[name];    icon = icon.substr(3);    icon = String.fromCharCode(parseInt(icon, 16));    return icon; };export default Icon;

profile.tsx

import React from 'react';import styles from '../assets/styles';import {  ScrollView,  View,  Text,  ImageBackground,  TouchableOpacity} from 'react-native';import Icon from '../components/Icon';const Profile = () => {return (<TouchableOpacity><Text style={styles.topIconLeft}><Icon name="chevronLeft" /></Text></TouchableOpacity>);}

This line of <Icon name="chevronLeft" />complains with an error of "JSX element type 'string' is not a constructor function for JSX elements.ts(2605)

Screenshot : enter image description here


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>