Comments (3)
It turns out these functions don't run (or don't seem to run) if these nodes later are altered when mounted into react using the functions from this library: https://github.com/pfefferniels/react-teirouter/tree/master
I don't understand why, but it doesn't seem to be a problem with you're code
from ceteicean.
@raffazizzi has code for working with CETEIcean in react. I think https://github.com/raffazizzi/react-teirouter is the right repo, but I couldn't swear to it. My sense though is that behaviors don't necessarily play well with react. I think Raff mostly just uses react components instead.
from ceteicean.
Hi @FransJoakim, with react-teirouter
, I would advise replacing CETEIcean behaviors with React components. You can attach a custom React component to tei-head
and handle it natively with React methods, state management, etc.
You probably already know from the react-teirouter
readme that you can route CETEIcean elements to React components, e.g.:
const domData // a DOM object, e.g. generated with CETEIcean.
<TEIRender data={domData}>
<TEIRoute el='tei-head' component={Head}/>
</TEIRender>
and the component (I'm trying to emulate your code above, but I didn't test this):
const Head = (props) => {
// you're determining the element to create dynamically so I can't use jsx here, but we can use React.createElement
return (
React.createElement(
"h" + props.teiNode.dataset.level, // element name
null, // no attributes needed
<TEINodes teiNodes={props.teiNode.childNodes} {...props} />} // content (I can use JSX again and this will append the content of tei-head)
)
)
}
(NB the main repo for tei-reactrouter is actually the one you're using, maintained by @pfefferniels; my fork is used only to send PRs to that repo).
Also note that tei-reactrouter
is a generic library to map React components to CETEIcean elements, so it won't include CETEIcean's default behaviors. However, I recreated most of them in React for a Gatsby theme. You can find the code here and you may be able to import it and use it even outside of a Gatsby enviroment; if you try it let me know how it goes! You should be able to install it via npm npm install gatsby-theme-ceteicean
.
It comes with default behaviors (modeled after the ones in vanilla CETEIcean) and you can Route them through react-teirouter
, eg:
import { TeiHeader } from "gatsby-theme-ceteicean/src/components/DefaultBehaviors"
// ...
<TEIRender data={domData}>
<TEIRoute el='tei-teiHeader' component={TeiHeader}/>
<TEIRoute el='tei-head' component={Head}/>
</TEIRender>
Alternatively, you don't need to use react-teirouter
, just use vanilla CETEIcean with React.useLayoutEffect()
, something like this, but it's less efficient and you lose the opportunity to use React with CETEIcean elements:
React.useLayoutEffect(() => {
// CETEI code to run after rendering
}, []) // <- note the empty array here
from ceteicean.
Related Issues (20)
- How to debug HOT 1
- Strange behaviour when attribute is missing HOT 4
- Further clean-up of the CETEIcean.css HOT 2
- Endnotes no longer work! HOT 1
- Tables are broken!
- Modularize the `note` behavior
- Add option to mute URL fragment parsing HOT 3
- Problem with behaviours HOT 3
- Use CETEIcean to extract and transform only a subelement of a TEI document HOT 3
- CETEIcean does not follow <xi:include/> entries HOT 2
- Manipulating CETEIcean output elements with JS document.querySelector('tei-p[attribute='value]') HOT 1
- alternate behaviors based on attribute values - example? HOT 1
- Declaring character entities with CETEIcean? HOT 3
- How to use CETEIcean server-side (if possible)? HOT 2
- Update spanish tutorial
- Babel seems to 'trip' over double semi-colon HOT 2
- pb behaviors not triggered
- Leading space before URL attribute causes .rw() method to assume an empty URL HOT 2
- confusing line in tutorial 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 ceteicean.