Unable to define context of sub-components using parent component's config
See original GitHub issue@frctl/fractal version: 1.1.3 + @frctl/nunjucks version: 1.0.3
I love Fractal so far, but I’m struggling a bit with including sub-components via method B (define context data in the parent componet’s config), documented here http://fractal.build/guide/components/sub-components#b-define-all-context-data-in-the-parent-component-s-config.
I’m using Nunjucks as my template engine, and .js files for component configs. Recreating the doc-example, I’m not able to pass in a different text to my button
using the parent component’s config.
{# button.njk #}
<button type="button" name="submit">{{ text }}</button>
// button.config.js
module.exports = {
title: 'Button',
context: {
text: 'A Button'
}
};
{# search-box.njk #}
<div class="searchbox">
<label for="search">{{ label }}</label>
<input type="search" name="keywords" id="search">
{% render '@button' %}
</div>
// search-box.config.js
module.exports = {
title: 'Search Box',
context: {
label: 'Search here',
button: {
text: 'Go!'
}
}
};
According to the documentation, I could expect the following result:
<!-- button.html -->
<button type="button" name="submit">A Button</button>
<!-- search-box.html -->
<div class="searchbox">
<label for="search">Search here</label>
<input type="search" name="keywords" id="search">
<button type="button" name="submit">Go!</button>
</div>
But instead I get the text “A Button” (defined in button.config.js
) in both cases:
<button type="button" name="submit">A Button</button>
<!-- search-box.html -->
<div class="searchbox">
<label for="search">Search here</label>
<input type="search" name="keywords" id="search">
<button type="button" name="submit">A Button</button>
</div>
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to update React Context from inside a child component?
Here I'm setting the defaults for language ('en') and a setLanguage function which will be sent by the context provider to the consumer(s)....
Read more >How To Share State Across React Components with Context
In this tutorial, you'll share state across multiple components using React context. React context is an interface for sharing information ...
Read more >How and When to Use Component Context in Svelte
Data added via setContext is only visible to the current component and its children; there is no way to alter the context of...
Read more >Breaking down CI/CD complexity with parent-child and multi ...
With parent -child pipelines we could break the configurations down into two separate tracks by having two separate jobs trigger child ...
Read more >Compound Components In React - Smashing Magazine
This tutorial explains how this can be achieved with the help of using the Context API and React to build components by using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @lucasctd. It’s actually better to include your CSS in the head of the preview layout: https://fractal.build/guide/components/preview-layouts
Hope this helps! 🙂
@lucasctd If you use Nunjucks, see 7iomka comment, if you use Handlebars:
Or to merge with component default context:
See Using Handlebars section on https://fractal.build/guide/core-concepts/views