adam-cowley / use-neo4j

React Hooks for Neo4j
MIT License
73 stars 21 forks source link

How to use useWriteCypher in React #6

Closed bmx1137 closed 3 years ago

bmx1137 commented 3 years ago

Hello, do you have an example of how to use the useWriteCypher hook?

I had const writeCypher = useWriteCypher(cypher) in a function component, but it would write to the database as soon as the component gets called/mounted. I would like to have a button that would construct cypher (create nodes and relationships) on the fly and write to the database upon clicking on the button. I have also tried binding useWriteCypher(cypher) to a button's onClick event or putting it inside a useEffect function but I would get this error message: React Hook "useWriteCypher" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function

Update: I got it working following the LazyQueries / UseLazyWriteCypher example. Thanks!! updateMovie({ id: int(0), updates: { title, plot } }) became updateMovie({}) (for now)

Thanks in advance! -bmx

adam-cowley commented 3 years ago

So you're all good now?

adam-cowley commented 3 years ago

No news is good news. Feel free to reopen the issue if you are still having problems.