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

Inner Input Field Loss Focus on Change #29

Open
zicodeng opened this issue Oct 24, 2018 · 0 comments
Open

Inner Input Field Loss Focus on Change #29

zicodeng opened this issue Oct 24, 2018 · 0 comments

Comments

@zicodeng
Copy link

Consider the following code:

import * as React from 'react';
import { adopt, Mapper, MapProps } from 'react-adopt';
import { Mutation, Query } from 'react-apollo';

import { MY_QUERY, MY_MUTATION } from 'graphql/queries';

interface AdoptRenderProps {
    myQuery: string;
    myMutation: () => void;
}

interface AdoptProps {
    render?: any;
}

export default class Search extends React.Component<
    {},
    {
        token: string;
    }
> {
    state = {
        token: '',
    };

    public render(): JSX.Element {
        const mapper: Mapper<AdoptRenderProps, AdoptProps> = {
            myQuery: ({ render }) => <Query query={MY_QUERY}>{render}</Query>,
            myMutation: ({ render }) => (
                <Mutation mutation={MY_MUTATION}>
                    {(mutation, result) => render({ mutation, result })}
                </Mutation>
            ),
        };

        const mapProps: MapProps<AdoptRenderProps> = ({
            myQuery,
            myMutation,
        }) => ({
            myQuery: myQuery.data,
            myMutation: myMutation.mutation,
        });

        const Composed = adopt(mapper, mapProps);

        return (
            <Composed>
                {({ myQuery, myMutation }) => {
                    const { token } = this.state;
                    return (
                        <form>
                            <input
                                type="text"
                                value={token}
                                onChange={this.handleInputChange}
                            />
                        </form>
                    );
                }}
            </Composed>
        );
    }

    private handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        this.setState({
            token: e.target.value,
        });
    };
}

Input field focus in lost immediately after I type a letter.

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