Socket
Socket
Sign inDemoInstall

jsxte

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsxte - npm Package Compare versions

Comparing version 2.0.1-canary-2fbaf0e276032505bfe291ac1d05d3840fcf8615.0 to 2.1.0

dist/cjs/jsx/prop-types/index.cjs

3

dist/legacy/index.js

@@ -33,4 +33,5 @@ "use strict";

__reExport(src_exports, require("./jsx/jsx.types.js"), module.exports);
__reExport(src_exports, require("./jsx/prop-types/index.js"), module.exports);
var import_context_map = require("./context-map/context-map.js");
var import_render_to_html = require("./html-parser/render-to-html.js");
var import_render_to_string_template_tag = require("./string-template-parser/render-to-string-template-tag.js");
var import_context_map = require("./context-map/context-map.js");
import "./utilities/array-flat-polyfill";
export * from "./express/index";
export * from "./jsx/jsx.types";
export * from "./jsx/prop-types/index";
export { defineContext } from "./context-map/context-map";
export { renderToHtml, renderToHtmlAsync } from "./html-parser/render-to-html";
export { renderToStringTemplateTag } from "./string-template-parser/render-to-string-template-tag";
export { defineContext } from "./context-map/context-map";
export type { ContextDefinition, ContextMap } from "./context-map/context-map";
export type { AttributeBool, HTMLProps } from "./jsx/base-html-tag-props";
export type { StringTemplateParserOptions } from "./string-template-parser/render-to-string-template-tag";
export type { ContextDefinition, ContextMap } from "./context-map/context-map";
export type { HTMLProps, AttributeBool } from "./jsx/base-html-tag-props";
export type { Crossorigin } from "./jsx/prop-types/shared/crossorigin";
export type { RefererPolicy } from "./jsx/prop-types/shared/referer-policy";
export type { Target } from "./jsx/prop-types/shared/target";

@@ -20,3 +20,3 @@ {

"name": "jsxte",
"version": "2.0.1-canary-2fbaf0e276032505bfe291ac1d05d3840fcf8615.0",
"version": "2.1.0",
"main": "./dist/legacy/index.js",

@@ -23,0 +23,0 @@ "types": "./dist/types/index.d.ts",

@@ -115,7 +115,7 @@ # JSX Template Engine

const myContext = defineContext<{ foo: string }>();
const myContext = defineContext<{ label: string }>();
const App: JSXTE.Component = (props, contextMap) => {
// Set the context to a new value, all descendants of this component will have access to it
contextMap.set(myContext, { foo: "Hello" });
contextMap.set(myContext, { label: "Hello" });

@@ -138,2 +138,53 @@ return <Foo />;

### Provider/Consumer Pattern
It is possible to incorporate a Provider/Consumer pattern with the ContextMap API.
```tsx
const makeContextWithProvider = <T,>() => {
const ctx = defineContext<T>();
const Provider: JSXTE.Component<{
value: T;
}> = (props, contextMap) => {
contextMap.set(ctx, props.value);
return <>{props.children}</>;
};
const Consumer = (
props: { render: (value?: T) => JSX.Element },
contextMap: ContextMap
) => {
if (contextMap.has(ctx)) {
const value = contextMap.get(ctx);
return <>{props.render(value)}</>;
} else {
return <>{props.render()}</>;
}
};
return {
context: ctx,
Provider,
Consumer,
};
};
// Use it
const MyContext = makeContextWithProvider<string>();
const App: JSXTE.Component = () => {
return (
<MyContext.Provider value={"Hello World!"}>
<div>
<MyContext.Consumer
render={(providedValue) => <h1>{providedValue ?? ""}</h1>}
/>
</div>
</MyContext.Provider>
);
};
```
## Extending the typings

@@ -140,0 +191,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc