Skip to content

Tag: jsx

Render curly braces as plain text in React/JSX

I am having problems displaying { and } as text in React. I saw a similar question that someone said to wrap the entire string in curlies, but this is not working: The return (<p>{“{{}}”}<p>) causes Is there an easy way to escape curly braces in jsx? Answer I think the issue is just a …

ESLint with React gives `no-unused-vars` errors

I’ve setup eslint & eslint-plugin-react. When I run ESLint, the linter returns no-unused-vars errors for each React component. I’m assuming it’s not recognizing that I’m using JSX or React syntax. Any ideas? Example: app.js Linter Errors: Here is my .eslintrc.json file: Answer Firs…

How to render HTML string as real HTML?

Here’s what I tried and how it goes wrong. This works: This doesn’t: The description property is just a normal string of HTML content. However it’s rendered as a string, not as HTML for some reason. Any suggestions? Answer Check if the text you’re trying to append to the node is not es…

Using boolean-value of attributes in JSX

I have a React.js project. I want to use data-picker plugin which require this style of input-attributes: But webpack doesn’t compile the app, when true is without quotes. Plugin doesn’t work, when true with quotes. What I should do? UPD. Yes, I run picker in componentDidMount() It works, but disp…

JavaScript/React Style Guide Indentation

Is there an agreed-upon convention for indentation in React JSX? 2 spaces, 4 spaces, tabs, etc. Answer You should just use the same indentation as the rest of your javascript code. That said react ecosystem seems to use mostly double spaces so I’d use that for consistency.