React-Code pen-Clone

·

2 min read

"In this blog post, I will be sharing one of my recent projects - a web application that allows users to write HTML, CSS, and JavaScript code in separate code editors and view the combined output in an iframe. This project was built using React and the React CodeMirror2 library. The purpose of this project was to provide a simple and easy-to-use interface for users to experiment with and test their front-end development skills."

  • The App component is the root component of the application, and it manages the state variables for the HTML, CSS, and JS code, and the final output.

  • The useState hook is used to initialize these variables and update their values when the user enters a new code.

  • The useEffect hook is used to update the final output whenever any of the code editors are changed.

  • The srcDoc attribute of the iframe element is set to a string that combines the HTML, CSS, and JS code entered by the user.

  • The useEffect hook is used to update this string whenever the HTML, CSS, or JS code is changed by the user.

  • The Editor component is a functional component that renders a CodeMirror code editor.

  • The useState hook is used to manage the open state variable, which determines whether the code editor is expanded or collapsed.

  • The ControlledEditor component from the React CodeMirror2 library is used to render the code editor and handle user input.

  • The onBeforeChange prop is used to update the state of the code variable whenever the user enters new code.

The options prop is used to configure various options for the CodeMirror editor, such as line wrapping, syntax highlighting, and auto-completion.

"In conclusion, this project has been a great learning experience for me. I've gained familiarity with CodeMirror and CodeMirror 2 libraries, as well as using state hooks and the iframe element. By building this project, I've improved my skills in web development and feel more confident in working with these tools. I look forward to continuing my learning journey by building more projects and exploring new technologies. Thank you for reading!"