Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RefObject<null>.current: any - Cannot assign to 'current' because it is a read-only property.ts(2540) #207

Open
m3c-ode opened this issue Mar 1, 2023 · 0 comments

Comments

@m3c-ode
Copy link

m3c-ode commented Mar 1, 2023

Hi there,

First, thank you for putting this package together!

I've been trying to use it with AntD, and I get an issue with TS here. In my example:

import { usePlacesWidget } from 'react-google-autocomplete';

function CreateAddressFields({ form }: Props) {
    const inputRef = useRef<any>(null);
    const options = {
        componentRestrictions: { country: ["ca", "us"] },
        fields: ["address_components", "geometry", "icon", "name"],
        types: ["address"]
    };

    const { ref, autocompleteRef } = usePlacesWidget({
        apiKey: PLACES_API_KEY,
        onPlaceSelected: (place, inputRef, something) => {
            console.log('place selected', place);
            const address = place.address_components;
        },
        options
    });

[...]

    return (
....
            <Form.Item
                label="Street Info 1:"
                name="street1"
                rules={[{ required: true, message: 'Please input your street1!' }]}>
                <Input
                    placeholder='Start typing for autofill...'
                    ref={(c) => {
                        inputRef.current = c;
       //Error here 
                        if (c) ref.current = c.input;
                    }}
                // ref={inputRef}
                />
            </Form.Item>
...

I get this TS error mentioned in the title.

I have tried changing the readonly prop, and making sure null was also included in the type, but I am unable to fix this.

Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant