conorhastings / react-native-syntax-highlighter

a syntax highlighter for react native using https://github.com/conorhastings/react-syntax-highlighter under the hood
MIT License
167 stars 25 forks source link

Update index.js #18

Closed mateosilguero closed 5 years ago

mateosilguero commented 5 years ago

I don't know why, but sometimes 'stylesheet' comes as an Array like this [{ stylesheet }, { opacity: 0.85 }], instead of an Object, so this throws an error referenced at issue #17 So, this is a workaround, if the stylesheet is an Array, returns the first element, wich is the actual style object.

conorhastings commented 5 years ago

do you have an example of when it comes in in an array or just random occurance?

mateosilguero commented 5 years ago

the error mostly happens when i press the component (onPress).

It's detailed here: https://github.com/conorhastings/react-native-syntax-highlighter/issues/17

throws TypeError: value.includes is not a function because Object.entries(style).reduce((newStyle, [key, value]) => { value is not a string, because style is not an object, is an array with this schema: [{ stylesheet }, { opacity: 0.85 }]

i have this component:

import React from 'react';
import SyntaxHighlighter from 'react-native-syntax-highlighter';
import { obsidian } from 'react-syntax-highlighter/styles/hljs';

const C = props =>
    <SyntaxHighlighter 
        language='javascript' 
        style={obsidian}
        fontSize={17}
        highlighter={'hljs'}                
    >
      {'console.log()'}
    </SyntaxHighlighter>;
conorhastings commented 5 years ago

got it, will merge for now while looking for al longer term solutiona

conorhastings commented 5 years ago

published as 2.0.1

mateosilguero commented 5 years ago

Awesome !

Should we close the issue #17 ?

Count on me for anything that i could help you to find the real problem.