Skip to content
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

Setting backgroundImage as in the React docs doesn't work #6

Open
jzabala opened this issue Oct 8, 2018 · 1 comment
Open

Setting backgroundImage as in the React docs doesn't work #6

jzabala opened this issue Oct 8, 2018 · 1 comment

Comments

@jzabala
Copy link

jzabala commented Oct 8, 2018

First, thanks for this library. I think it is really cool :)

When I try to set the background image to the style object as in the React documentation it doesn't work. Example code:

const divStyle = {
  color: 'blue',
  backgroundImage: 'url(' + imgUrl + ')',
};

function HelloWorldComponent() {
  return <div style={divStyle}>Hello World!</div>;
}

Checking the code I think the problem is here:
https://github.com/alecsgone/jsx-render/blob/6e8053e67b460a2cdcb8585dc606d6b8da5fd3ce/src/dom.js#L24

The objectToStyleString function doesn't take into account the camelCase.

You can hack this just by setting the background image this way:

const divStyle = {
  color: 'blue',
  'background-image': 'url(' + imgUrl + ')',
};

function HelloWorldComponent() {
  return <div style={divStyle}>Hello World!</div>;
}

But I don't think this is a good solution because it is not compatible with how react currently works.

I think a better solution would be to loop over the style object and set each prop directly to the element.style object.

I can create a PR for this if you like.

@alexrqs
Copy link
Owner

alexrqs commented Nov 29, 2018

Totally, PRs are welcome I'll dig into this later, thanks for raising the issue 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants