Giter Site home page Giter Site logo

Comments (4)

tjbaron avatar tjbaron commented on September 28, 2024 5

A cleaner way to trigger rerender is by changing the “key” prop of NodeEditor to a new value. For example, the name or position of the tab the user navigates to.

const [tab, setTab] = useState(“default”);
return <>
    <Tabs>
        <Tab onClick={()=>setTab(“default”)} />
        <Tab onClick={()=>setTab(“other”)} />
    </Tabs>
    <Holder><NodeEditor key={tab} nodes={nodesForTab[tab]} ... /></Holder>
</>

from flume.

chrisjpatty avatar chrisjpatty commented on September 28, 2024 1

@augusto3691 I'd definitely like to get you a better API to do this than to have to force re-render the component with a setTimeout. I'll get that added to my list of upcoming features.

from flume.

augusto3691 avatar augusto3691 commented on September 28, 2024

hi @CyrilDelvalle-Actronika, we managed to do that with useEffect hooks:

...
const nodeEditor = React.useRef()
const [nodes, setNodes] = useState();
const [nodesInEditor, setNodesInEditor] = useState();
const [showNodeEditor, setShowNodeEditor] = useState(true);

useEffect(() => {
        if (nodes !== undefined) {
            setShowNodeEditor(false)
            setTimeout(() => {
                setShowNodeEditor(true)
            }, 1)
        }
}, [nodes])

...
return (
{
    showNodeEditor &&
    <NodeEditor
        ref={nodeEditor}
        portTypes={config.portTypes}
        nodeTypes={config.nodeTypes}
        onChange={setNodesInEditor}
        nodes={nodes}
    />
}
)

We are doing that to achieve a "save / load" system, maybe can help you :)

from flume.

augusto3691 avatar augusto3691 commented on September 28, 2024

@chrisjpatty i agree with you that setTimeout is not the most elegant solution but for my pruposes is not affecting the user experience or the performance, your working is amazing, ansious by #74 hahahah

from flume.

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.