Create custom component using reactive
#434
Closed
sandheep45
started this conversation in
General
Replies: 1 comment
-
I figured out the issue in my code. I didn't wrap the // ReactiveInput.tsx
import { BindKeys, FCReactive, reactive } from "@legendapp/state/react";
import { Input, InputProps } from "../ui/input";
import { ChangeEvent, createElement } from "react";
type IReactive = FCReactive<typeof Input, InputProps>;
const bindInfoOneWay: BindKeys = {
value: {
handler: "onChange",
getValue: (e: ChangeEvent<HTMLInputElement>) => e.target.value,
defaultValue: "",
},
};
const ReactiveInput = reactive(
(props: InputProps) => createElement(Input, props),
[],
bindInfoOneWay,
) as unknown as IReactive;
export default ReactiveInput; // App.tsx
const App = observer(() => {
const inputState$ = useObservable("");
return (
<div>
<ReactiveInput $value={inputState$} />
{inputState$.get()}
</div>
);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create a custom Input component using
reactive
and here is the code i am using to do soi have taken some reference for the below code from here
i have alseo tried the following code as well (taken reference from here)
but both of the above appraoch doesn't seem to work. The
Input
component which i am importing from../ui/input
is the input component from shadcn ui and i have mentioned the code belowThis is the kind of implementation (two way binding) i want to acheive
I am also getting the following error from the
ReactiveInput
Property '$value' does not exist on type 'IntrinsicAttributes & Omit<Omit<Omit<DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "ref"> & RefAttributes<...>, "ref">, never> & {}'. Did you mean 'value'? ts (2322) [8, 22]
I am not getting if am i doing something wrong or am i missing something somewhere or it's something else. Any kind of help is highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions