I’ve built this solution to the Markdown Previewer. I believe it passes all the tests, but the automated tests are showing it is failing test 6:
" When my markdown previewer first loads, the default markdown in the #editor field should be rendered as HTML in the #preview element"
To my eyes, the solution I’ve created works and passes this test, but it would be great to know if there is something wrong as suggested by the automated test.
I would suggest using a
useEffect with an empty dependencies array that calls the
setText setter with the default markdown.
Thank you very much for the steer! It led me to reading up on useEffect, which was interesting in itself, and helped me find a couple of bugs in my code. Without your input, I wouldn’t have found them! Much appreciated - thank you. All tests are now passed.
Happy to have helped.
useEffect is a must to know about when using functional components. You will be using it for data fetching, and side effects. One mental model that can also be helpful is to think of it as a “state synchronizing” function.
Thank you so much for taking the time to reply. The first link 'How to useEffect in React’I found very clear, and I’ve tweaked my solution to use ‘useEffect’ and it’s working great. The second article I’ve started to read, but I need more time to finish it. Thank you again for the steer - much appreciated.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.