RenderBlocks

What is RenderBlocks

Setup

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- RENDERBLOCKS -->
<script src="http://www.alexmercedcoder.com/renderBlocks.js" charset="utf-8" defer></script>
<!-- YOUR CODE -->
<script src="app.js" defer></script>

</head>
<body>

</body>
</html>

Your First Block

const app = new RenderBlock({
target: "#app",
render: block => `<h1>Hello World</h1>`
})
<body>
<div id="app"></div>
</body>

Props

<div id="app" hello="Hello World"></div>const app = new RenderBlock({
target: "#app",
render: block => {
const {props} = block
return `<h1>${props.hello}</h1>`
}
})

Info

const app = new RenderBlock({
target: "#app",
render: block => {
const {props, info} = block
return `<h1>
${props.hello}
</h1>
<button>
${info.button}
</button>`
},
info: {
button: "Click Me"
},
after: (block) => {
document.querySelector('button').addEventListener('click', () => {
block.updateInfo('button', 'I have been clicked')
})
}
})

Bottom Line

--

--

Alex Merced is a Developer Advocate for Dremio and host of the Web Dev 101 and Datanation Podcasts.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Merced Coder

Alex Merced is a Developer Advocate for Dremio and host of the Web Dev 101 and Datanation Podcasts.