/BrandSurvey-React

some simple HTML content and using firebase to store the survey result

Primary LanguageJavaScript

Notes

使用refs

findDOMNode(this.refs.MyName.value)

同等於:

this.refs.MyName.value

this.refs

<FormControl>會回傳undefined,在一般的<input>沒這個困擾可以像前述照用

<FormControl
  inputRef={(ref) => { this.input = ref }}
/>
handleNameSubmit(event) {
    event.preventDefault()
    this.setState({ name: this.input.value })
  }

using firebase(w/o authentication) uuid

  • refs: 1

uuid用來產生獨一無二的亂數

// App.js
this.state = {
  id: uuid.v1(),
}

每個id都是獨一無二的亂碼路徑,所以直接set({...})

firebase.database().ref('survey/' + this.state.id).set({
  name: this.state.name,
  answers: this.state.answers
})