Improve types for Html2React processors
See original GitHub issueDescription
Right now, using TypeScript when declarating a processor for the Html2React package has some problems (see discussion here: https://github.com/frontity/frontity/commit/f7f2e6eab85889465764ae70d1fe73364db5b0ad#r37684196):
node
type is not inferred correctly and a type guard is needed to consider it of typeElement
.parent
andchildren
nodes cannot be typed with the current implementation. Also, the default props type of this nodes isunknown
which is not a good default type.
Possible solution
To solve this issue, the idea is to pass not only the types of the props but the type of the element as well and its parent
and children
attributes. Some of this attributes could be optional and the final types would be the passed types merged with a default type.
E.g.
type LazyImgWrapper = {
type: "element";
component: "figure";
children: [LazyImg];
}
type LazyImg = {
type: "element";
component: "img";
props: { "data-src": string };
parent: LazyImgWrapper;
};
const myProcessor: Processor<LazyImg> = {
test: ({ node }) => { },
processor: ({ node }) => {
node.props["data-src"] // <- this should be of type `string`
node.parent.component // <- this should be of type `"figure"`
}
};
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Working with processors - Frontity Docs
The processor property is a function that in some way "processes" the received node (remember that a node is a JavaScript object representing...
Read more >frontity/html2react - api-reference - GitHub
This package is in charge of converting HTML to React. It works with processors that match HTML portions and replaces them with React...
Read more >Frontity Talks 2020-05 - Contact Form 7 & Processors - YouTube
In this episode of #FrontityTalks we cover two topics. Michael demonstrates how to use beforeSSR to pre-fetch data, in this case a contact ......
Read more >Connecting Gutenberg and Frontity - DevPress - CSDN
In the same way that WordPress usage is increasing each year and is the ... import { Element,Processor } from "@frontity/html2react/types"; ...
Read more >How to build a headless WordPress website with Frontity ...
The current Frontity state is used to know which post type * should be rendered. ... libraries.html2react.processors array. <Content>
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
We’d have to refractor the definition of some of the interfaces. The reason is that we have a problem with inferring the types of.
The proposed approach to solving this issue include replacing the default type definitions, exposing the interfaces for
Element
,Text
andComment
so users can define custom interface be made by extending them.@DAreRodz is currently working on these features and will keep working on it till it’s done. So, if you have any questions, please, do ask him.
@darerodz, I have assigned this to you as well, as you are going to work on this together.
Could you please keep here a record of what’s going on?