Replies: 2 comments 5 replies
-
Try: <>
<svg
id="svg"
onload="autoBox()"
style={'visibility: hidden'}
width="100%"
height="100%"
xmlns="http://www.w3.org/2000/svg"
>
{this.props.children}
</svg>
<script>
{`
"use strict";
function autoBox() {
console.log('autoBox');
const svg = document.querySelector('svg');
const size = svg.getBBox();
svg.setAttribute('viewBox', '0 0 ' + size.width + ' ' + size.height);
svg.style.visibility = 'initial';
}
var svg = document.getElementById("svg");
svg.onload = autoBox;
`}
</script>
</> Also, if you add inline scripts, I recommend transpiling it with babel first: https://babeljs.io/repl |
Beta Was this translation helpful? Give feedback.
4 replies
-
In React and Preact you have a function named cloneElement to add props/attributes to the props.children object. It works both on ssr and csr on both components and normal nodes. I use it like this when I need my parent to edit some values of the its children
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In SSR when I was using preact's renderToString I was able to write some code like this (to add small fast interactivity in a component)
Which was really cool cause I was able to have the js fromatted as js in vs code and I was still able to ship the function to the broser and reference it in the onload attribute of the component
In nanojsx for some reason the onchange attribute gets removed and the function inside the <script> tag gets exectued
I have to do it like this, which still works but I cannot bind the function using event attributes and also I don't have the nice js formatting but instead I see it as a string.
Someone knows any nice and clean Idea to to do this with nanojsx?
Beta Was this translation helpful? Give feedback.
All reactions