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

defaultValue don't works #81

Closed
tarsisazevedo opened this issue Oct 26, 2015 · 1 comment
Closed

defaultValue don't works #81

tarsisazevedo opened this issue Oct 26, 2015 · 1 comment

Comments

@tarsisazevedo
Copy link

I start using react-autosuggest and it's an amazing react component. But I have a problem when I try to set up defaultValue. I wrap autosuggest in another react component because project needs.

var VideoSuggest = React.createClass({
    getInitialState: function(){
        return {
            value: ""
        }
    },
   getSuggestions: function(input, callback) {
        ...
    },
    componentDidMount: function() {
        this.onInputChange(this.props.value);
    },
    suggestionSelected: function(suggestion, e) {
        e.preventDefault();
        this.setState({value: suggestion})
        this.props.handler(this.props.aKey, suggestion, "http://semantic-api/test");
    },
    onInputChange: function(value) {
        this.setState({value: value})
        this.props.handler(this.props.aKey, value, "http://semantic-api/test");
    },
    render: function() {
        var inputAttr = {
            placeholder: this.props.type,
            className: "",
            onChange: this.onInputChange
        }
        return (
            <li ref={this.props.key}>
                <Autosuggest
                inputAttributes={inputAttr}
                suggestions={this.getSuggestions}
                onSuggestionSelected={this.suggestionSelected}
                defaultValue={this.state.value}/>
            </li>
        )
    }
});

In react debugger defaultValue is ok but state.value not.
screen shot 2015-10-26 at 1 03 52 pm

What's wrong?

@tarsisazevedo
Copy link
Author

I update the component and it works! sorry :)

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