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

Publish as package #1

Open
SimeonC opened this issue Jun 27, 2017 · 1 comment
Open

Publish as package #1

SimeonC opened this issue Jun 27, 2017 · 1 comment

Comments

@SimeonC
Copy link

SimeonC commented Jun 27, 2017

Hi @zhaoyao91.

Thanks for figuring this out and putting up a repository it's saved me a fair bit working with Japanese IME. As it looks like it could be quite a while until react fix this properly, would it be possible to get this published on NPM? I'm happy to help out.

I needed to extend your code to allow getting the ref which is kind of hard so I ended up with this:

export default class OptimisticInput extends Component {
  static propTypes = {
    value: PropTypes.string,
    onChange: PropTypes.func,
    getRef: PropTypes.func
  };

  static defaultProps = {
    value: '',
    onChange: noop,
    getRef: noop
  };

  constructor(props, context) {
    super(props, context);
    this.state = {
      value: props.value
    };
  }

  componentWillUpdate(nextProps, nextState) {
    if (nextProps.value !== this.props.value && nextProps.value !== nextState.value) {
      this.setState({ value: nextProps.value });
    }
  }

  onChange = (e) => {
    this.setState({
      value: e.target.value
    });
    this.props.onChange(e);
  }

  render() {
    const { getRef, ...props } = this.props;
    return <input {...props} ref={getRef} value={this.state.value} onChange={this.onChange} />;
  }
@zhaoyao91
Copy link
Owner

Hi, thanks for your suggestion. But this repo is just for inspiration. You can publish your package and make it more robust and suit for your cases and share it. :)

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

2 participants