Giter Site home page Giter Site logo

Comments (3)

FransJoakim avatar FransJoakim commented on August 20, 2024

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.

hcayless avatar hcayless commented on August 20, 2024

@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.

raffazizzi avatar raffazizzi commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.