doubt about editing returned raw VNodes
See original GitHub issueIm trying to edit raw ‘h’ nodes before they get constructed
Hope u get a bit of background how im trying to do that
Im trying to create a @withStyle(cssObj)
decorator using a @afterMethod
Join Point with kaop-ts
to plug a <style> ... content </style>
inside some component before it gets evaluated by preact
.
Because this occurs in runtime im trying to dynamicly edit component’s render() hyperscript result before it become a VNode placing a preact_1.h("style", null, scopedRules)));
as the last children.
My question is if there is somehow a way more friendly to edit hyperscript rather than str.replace(regexThatSearchOnHyperScriptBodyFunctionTheLastChildren, "preact_1.h("style", null, scopedRules)))")
:\
The resulting implementation will look like this:
import { h, Component } from "preact";
// styles will be replaced with component scoped selectors like angular 2+ does
const styleContent = `
button {
color: gray;
}
button:hover {
color: white;
}
`;
export class MyButton extends Component {
@withStyle(styleContent)
render(props) {
return (
<button>{props.children}</button>
)
}
}
or
export const MyButton = withStyle(styleContent)(props => (
<button>{props.children}</button>
));
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top GitHub Comments
working decorator implementation:
Awesome answer, thanks