Skip to main content
Converting html template to React project
- First lets find the template that we want to use. This is the perfect place to find really good html5 responsive site template. https://html5up.net/
- I am choosing this theme for this example. https://html5up.net/striped
- Go ahead, download the zip file, and extract to your local folder.
- Lets create a startup react app. I am using, https://github.com/facebook/create-react-app . But you can use any other tool or you can configure your project.
- After installation, run create-react-app your-project-name . I have given my project name, "templatetoreact"
- You can simply run the app with command, npm start. for other options please check the create react app documentation. After, npm start, react project will be lunched http://localhost:3000
- Open the project in your code editor. Preferred code editor https://code.visualstudio.com/
- After opening the project, copy your template's assets and images folder to your project public folder. And also, you can copy whole template's content onto public > template folder.
- Now, you can browse the template, with this url, http://localhost:3000/template/ . Your template should be up and running.
- Now, first copy the head section of template html to project's index.html ( under public > index.html ). You can replace all or preserve something like favicon.
- Now loads all the scripts tag from template index.html to projects index.html after body tag ends. ( It looks like jquery lite with react bundle overriding the template jquery configuration if we put scripts in the body) Your project should still be running without any problem. Check on : http://localhost:3000/
- Now, its time to fix the template html so that it will be easier to move them in jsx file. If you don't know what are jsx file in react, please refer to https://reactjs.org/docs/introducing-jsx.html
- Open template's index.html and
- Remove all html comments line
- Remove the content inside app.js > render > html like elements, and replace with your fixed template index.html divs. Make sure to wrap all divs to parent div.
- Find and replace "class" with "className"
- Browse, http://localhost:3000/ and look at the console for additional error related to html. Fix them. In my case it was "colspan" to "colSpan"
- Just Save
- Your app, should be up and running. Now, we can start componizing the template html elements to react component.
Comments
Post a Comment