# DISCUSSION: Qwik Component + Handlers + State ###### tags: qwik ## Overview Brainstorm how should Qwik handle component templates, handlers, state and styles. ## Related - [DISCUSSION: Qwik Component Stylesheet Handling](/2g3LZuAfTaShUePul8XDxg) ## Goals - Component, handler, and state initializer need to be separated. ## Example **File: `counter.component.tsx`** ```typescript import {increment, decrement} from './counter.handler'; export const Counter = qComponent( 'div', { class: 'counter' }, async function Counter(this: ComponentRef, props: {value?: number}) { const state = getState(this) return (<> <button on:click={increment}>+</button> Count: {state.count} <button on:click={decrement}>-</button> </>); } ); ``` **File: `counter.state.tsx`** ```typescript= export CounterState { count: number; } ``` **File: `counter.handler.tsx`** ```typescript export async function increment(state: CounterState) { state++; } export async function decrement(state: CounterState) { state--; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up