import { useState } from "react"; export const Counter = ({ initValue }: { initValue: number }) => { const [value, setValue] = useState(initValue); return( <> <div>{value}</div> <button onClick={() => setValue(value + 1)}> Increment </button> </> ); };
import { useState } from "react"; export const Counter = ({ initValue }: { initValue: number }) => { const [value, setValue] = useState(initValue); return( <> <div>{value}</div> <button onClick={() => setValue(value + 1)}> Increment </button> </> ); };
import { ReactRegistry } from "@camertron/live-component"; ReactRegistry.register_component("Counter", Counter);
import { ReactRegistry } from "@camertron/live-component"; ReactRegistry.register_component("Counter", Counter);
<%= render(LiveComponent::React.new(component: "Counter", initValue: 1)) %>
<%= render(LiveComponent::React.new(component: "Counter", initValue: 1)) %>
class CounterComponent < ViewComponent::Base include LiveComponent::Base def initialize(**kwargs) @kwargs = kwargs end end
class CounterComponent < ViewComponent::Base include LiveComponent::Base def initialize(**kwargs) @kwargs = kwargs end end
<%= render(LiveComponent::React.new(component: "Counter", **@kwargs)) %>
<%= render(LiveComponent::React.new(component: "Counter", **@kwargs)) %>
import { live, LiveController } from "@camertron/live-component"; type CounterComponentProps = { initValue: number; } @live("CounterComponent") export class CounterComponent extends LiveController<CounterComponentProps> { do_something() { this.render((component) => { // Your logic here. When the component re-renders, props will automatically // get passed to the React component. }); } }
import { live, LiveController } from "@camertron/live-component"; type CounterComponentProps = { initValue: number; } @live("CounterComponent") export class CounterComponent extends LiveController<CounterComponentProps> { do_something() { this.render((component) => { // Your logic here. When the component re-renders, props will automatically // get passed to the React component. }); } }
1 | <%= render( |
2 | LiveComponent::React.new( |
3 | component: "Counter", **@kwargs |
4 | )
|
5 | ) %> |
1 | <%= render( |
2 | LiveComponent::React.new( |
3 | component: "Counter", **@kwargs |
4 | )
|
5 | ) %> |
1 | class CounterComponent < ViewComponent::Base |
2 | include LiveComponent::Base |
3 | |
4 | def initialize(**kwargs) |
5 | @kwargs = kwargs |
6 | end
|
7 | end
|
1 | class CounterComponent < ViewComponent::Base |
2 | include LiveComponent::Base |
3 | |
4 | def initialize(**kwargs) |
5 | @kwargs = kwargs |
6 | end
|
7 | end
|
1 | import { live, LiveController, ReactRegistry } from "@camertron/live-component"; |
2 | import { useState } from "react"; |
3 | |
4 | export const Counter = ({ initValue }: { initValue: number }) => { |
5 | const [value, setValue] = useState(initValue); |
6 | |
7 | return( |
8 | <>
|
9 | <div>{value}</div> |
10 | <button onClick={() => setValue(value + 1)}> |
11 | Increment |
12 | </button> |
13 | </>
|
14 | );
|
15 | };
|
16 | |
17 | ReactRegistry.register_component("Counter", Counter); |
18 | |
19 | type CounterComponentProps = { |
20 | initValue: number; |
21 | }
|
22 | |
23 | @live("CounterComponent") |
24 | export class CounterComponent extends LiveController<CounterComponentProps> { |
25 | do_something() { |
26 | this.render((component) => { |
27 | // Your logic here. When the component re-renders, props will automatically
|
28 | // get passed to the React component.
|
29 | });
|
30 | }
|
31 | }
|
1 | import { live, LiveController, ReactRegistry } from "@camertron/live-component"; |
2 | import { useState } from "react"; |
3 | |
4 | export const Counter = ({ initValue }: { initValue: number }) => { |
5 | const [value, setValue] = useState(initValue); |
6 | |
7 | return( |
8 | <>
|
9 | <div>{value}</div> |
10 | <button onClick={() => setValue(value + 1)}> |
11 | Increment |
12 | </button> |
13 | </>
|
14 | );
|
15 | };
|
16 | |
17 | ReactRegistry.register_component("Counter", Counter); |
18 | |
19 | type CounterComponentProps = { |
20 | initValue: number; |
21 | }
|
22 | |
23 | @live("CounterComponent") |
24 | export class CounterComponent extends LiveController<CounterComponentProps> { |
25 | do_something() { |
26 | this.render((component) => { |
27 | // Your logic here. When the component re-renders, props will automatically
|
28 | // get passed to the React component.
|
29 | });
|
30 | }
|
31 | }
|
1 | <%= render(CounterComponent.new(initValue: 1)) %> |
1 | <%= render(CounterComponent.new(initValue: 1)) %> |