Comments (2)
If I understand correctly, then I actually haven't ran into that specific scenario. I have had cases where I've used non-React components that handle their own rendering given a DOM node, such as the CodeMirror
component in the GitHub snippet recorder example.
So, currently Karet doesn't provide explicit support for the scenario where one wants to perform ad hoc DOM manipulation after each update. You can, of course, do rendering on your own. Something like this (untested draft code):
const Code = ({code}) => {
const element = U.variable()
const updateEffect = U.thru(
U.template({element, code}),
U.consume(({element, code}) => {
element.innerHTML = code.replace(/[\u00A0-\u9999<>&]/gim, i => '&#' + i.charCodeAt(0) + ';')
syntaxHighlight(element)
})
)
return <pre ref={U.refTo(element)} {...{updateEffect}}/>
}
If there is enough need for such a thing, then one possibility would be to e.g. support a special property, say karet-onDidUpdate
, which would allow one to perform updates after rendering. Something like this:
const Code = ({code}) =>
<pre karet-onDidUpdate={element => syntaxHighlight(element)}>
{code}
</pre>
There are probably other plausible APIs for this sort of thing.
However, it is not clear to me whether it makes sense to provide explicit support for this. I suspect that this kind of thing probably only works for very simple cases (such as the above) in the sense that one can't e.g. reliably and portably (as in having the code work with future React versions) render non-trivial DOM using React and then modify that arbitrarily after each update.
from karet.
FYI, I added a Highlight
component to the GitHub Snippet Recorder example that uses Highlight.js to highlight a code block after changes (just edit the text in the CodeMirror editor on top).
from karet.
Related Issues (15)
- Consider supporting `React.cloneElement` HOT 1
- Breaking change: reconsider exports HOT 1
- Support different VDOM implementations HOT 6
- Support arbitrarily nested children
- Do not call `forceUpdate` during mounting HOT 2
- Lift contents of `dangerouslySetInnerHTML` HOT 1
- How does it work? HOT 2
- Implement template string helpers for detecting observers HOT 1
- Accept ES7 Observables instead of Kefir HOT 3
- Help needed in porting this to RxJS HOT 3
- karet and lists of children HOT 1
- Provider to support children with observables HOT 1
- Pass through React Hooks
- Add jsx-runtime support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karet.