Empty Element Renders
See original GitHub issueFollowing the directions on your README and this blog, I keep getting an empty element that doesn’t show the svg. Any ideas?
My svg file is proper.
webpack.config.js (or at least the one that matters, I have configs for each environment but they webpack-merge
with this one):
// webpack config
const webpack = require('webpack');
const path = require('path');
module.exports = function() {
return {
context: path.join(__dirname, '..', '..'),
entry: './src/index.jsx',
output: {
path: './build/',
filename: 'bundle.js',
sourceMapFilename: 'map',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: 'babel-loader',
}, {
test: /\.svg$/,
include: /assets/,
use: ['babel-loader', 'svg-react-loader'],
}
]
},
resolve: {
modules: [
'node_modules',
],
},
};
};
chatBubble.jsx:
import React from 'react';
import ReactDOM from 'react-dom';
import bubbleIcon from '../assets/bubble.svg'; // TODO: doesn't show properly yet
const buttonStyle = {
width: 500,
height: 500,
position: 'absolute',
bottom: 3,
right: 3
};
const bubbleButton = () => (
<button style={buttonStyle}>
<bubbleIcon />
<span>bubble</span>
</button>
);
export default bubbleButton;
index.jsx (mainly for HMR):
import React from 'react';
import ReactDOM from 'react-dom';
// AppContainer is a necessary wrapper component for HMR
import { AppContainer } from 'react-hot-loader';
import chatBubble from './chatBubble.jsx';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<Component/>
</AppContainer>,
document.getElementById('root')
);
};
render(chatBubble);
// Hot Module Replacement API
if (module.hot) {
module.hot.accept('./chatBubble.jsx', () => {
render(chatBubble)
});
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How to return an empty jsx element from the render function in ...
Just in case anyone want another approach: Since React v16.2 you can use Fragments allowing to add an empty JSX tag like this:...
Read more >Fragments - React
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding...
Read more >What are React Fragments or the React Empty Tags ... - Medium
This is called the Empty tag in React. This is a shorter syntax for React Fragments.
Read more >Empty tag syntax: <> | Can I use... Support tables for HTML5 ...
The React framework offers a shorthand syntax for fragment components that appears as an empty tag: <></> . While it is supported in...
Read more >empty - CSS: Cascading Style Sheets - MDN Web Docs
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
your problem in
import bubbleIcon from '../assets/bubble.svg';
component name))) Please read react docsThanks @gibson I had the same issue