Comments (1)
I got this working in a very crude manner. At the minute I have to ensure all my views are wrapped in the LayoutContainer that then uses context to determine what layout to load the view within.
I think it would be cleaner if I could create my views and layouts separately and have the TSX-views engine piece it together using the default view specified in config, or passed view the render method.
export default function LayoutContainer(props: any): ReactElement {
const context = useContext(DefaultContext);
let LayoutComponent;
if (context.layout) {
try {
const module = require(context.layout);
LayoutComponent = module.default;
} catch (error) {
console.log(`Error loading layout '%s'`, context.layout)
}
}
return LayoutComponent ? <LayoutComponent>{props.children}</LayoutComponent> : <>{props.children}</>;
}
Another thought I had was if there was a mechanism to have context globally available to views. For example res.locals. not played with this yet, but I think again if the TSX engine should perhaps have a default context that it makes available.
from express-tsx-views.
Related Issues (12)
- Style HOT 3
- Action Required: Fix Renovate Configuration
- Nest.js Setup Throws Error For App Context HOT 1
- ES Module HOT 6
- Interactivity. HOT 2
- How to use it as second render engine.
- adding support for webpack, babel,scss,css, transpile modules HOT 1
- On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:' HOT 1
- TypeError: Cannot read property 'createElement' of undefined HOT 1
- Incorrect view engine extension HOT 5
- NestJS -Failed to lookup view in views directory HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-tsx-views.