
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@containrz/stencil-decorator
Advanced tools
`@containrz/stencil-decorator` is a simpe decorator to help you manage your global and local states without any need for configuration and no dependency on context.
@containrz/stencil-decorator
is a simpe decorator to help you manage your global and local states without any need for configuration and no dependency on context.
In order to use @containrz/stencil-decorator
, you need to create a class that extends Container
, provided on the package.
import { Container } from '@containrz/stencil-decorator'
interface User {
name: string
email: string
phoneNumber: string
}
export class UserContainer extends Container<User> {
public state = {
name: '',
email: '',
phoneNumber: '',
}
public setUser = (user: User) => this.setState(user)
public setName = (name) => this.setState({ name })
public setEmail = (email) => this.setState({ email })
// ...
}
Once you have your container, you can now start sharing its state:
import { Component, VNode } from '@stencil/core'
import { UseContainer } from '@containrz/stencil-decorator'
import { UserContainer } from './UserContainer'
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
@UseContainer(UserContainer) userData: UserContainer
render(): VNode {
return (
<div>
<input
value={this.userData.state.name}
onChange={e => this.userData.setName(e.target.value)}
/>
<p>{this.userData.state.name}</p>
</div>
)
}
}
In case you need to create a container based on a prop, you can also register it in a different way:
import { Component, VNode } from '@stencil/core'
import { registerContainer } from '@containrz/stencil-decorator'
import { UserContainer } from './UserContainer'
@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true,
})
export class MyComponent {
@Prop() userId: string
private userData: UserContainer
componentWillLoad(): void {
this.test = registerContainer(new UserContainer(this.userId), this)
}
render(): VNode {
return (
<div>
<input
value={this.userData.state.name}
onChange={e => this.userData.setName(e.target.value)}
/>
<p>{this.userData.state.name}</p>
</div>
)
}
}
FAQs
`@containrz/stencil-decorator` is a simpe decorator to help you manage your global and local states without any need for configuration and no dependency on context.
We found that @containrz/stencil-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.