I am learning javascript, specifically, react.js,I am following a basic redux tutorial, but having problems in understanding the folowing jsx syntax.
import React from 'react'
import { connect } from 'react-redux'
import { addTodo } from '../actions'
let AddTodo = ({ dispatch }) => {
let input
return (
<div>
<form
onSubmit={e => {
e.preventDefault()
if (!input.value.trim()) {
return
}
dispatch(addTodo(input.value))
input.value = ''
}}
>
<input
ref={node => {
input = node
}}
/>
<button type="submit">
Add Todo
</button>
</form>
</div>
)
}
AddTodo = connect()(AddTodo)
export default AddTodo
On searching what I could only figure out is that ref is a prop for reference (similar to a unique Id) that helps us identifying elements and do stuff with them.
My Question(s): If I understand ref correctly, (please correct me if I am wrong)
(a) In the above example what will be the possible value of the prop ref. In other words, how will the element look when it is actually rendered on the web page?
(b) What does node here refers to? Does the function node => { input = node } return anything?