-
Notifications
You must be signed in to change notification settings - Fork 83
Handling css as "string" to react as "object" conversion #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah, you just need to Object.assign the result of this library to style. Should work then |
Honestly, an example of that in the readme would just save people's time. I didn't quite understand how to use your main function from the examples. |
Sorry, ignore my previous answer - it's not the best way to be doing things The real answer is you want a CSS parser, because your code doesn't handle things like semi-colons appearing in comments or strings. There's no example like you posted in the readme for this reason But if you're happy with that edge case, you were almost there with your code. This library accepts an array of const rules = css.split(';');
const tuples = map(rules, (rule) => {
let [key, value] = rule.split(':');
if (key && value) {
key = key.trim();
value = value.trim();
return [key, value];
} else {
return null;
}
}).filter((x) => {
return x != null;
});
cssToReactNative(tuples); |
Closing, but feel free to continue the discussion if you want |
I was looking for a lib to convert a string to react object.
I used this lib to do so, I believe the following function could be a good addition to the current library. Feel free to add it!
The text was updated successfully, but these errors were encountered: