Answer the question
In order to leave comments, you need to log in
How to organize React templates in separate files?
I started working with react, and I'm interested in such a possibility as splitting templates with components into different files. For example, to have such a file structure react/components/SomeComponent.jsx
and react/templates/SomeComponent.jsx
. So that I can simply write in the component
const ComponentTemplate = require('templates/SomeComponent');
, and in the render method write this:render() {
return ComponentTemplate;
}
text-loader
. And is this practice generally normal with respect to react?
Answer the question
In order to leave comments, you need to log in
I do not really understand why separate the template and the component? In React, a component is a small piece with its own logic, template, and even styles.
As an option, or use wix.github.io/react-templates
//templates/templat.js
import React from 'react';
export default function() {
return <div>Template</div>
}
// component.js
render() {
return require('templates/template')()
}
Take a look at the resolve section in the webpack documentation . In particular resolve.root, resolve.modulesDirectories and resolve.extensions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question