reactjs - Value of i parameter in props ind is not changing -
code snippet:
function button(props) { var ans = [ ["56","30","11","20"],["1","-2","2","-1"], ["odd","even","none","both"] ]; var button = [], i; for(i = 0; <= 3; i++) { button.push(<button key={i} onclick={()=>props.ind(i)}> {ans[props.q-1][i]} </button>) } return (<div>{button}</div>) }
i newbie @ using fatarrows , react.i making quizzing interface.here each of 4 buttons (i=0 3) holds choice specific question no.(q) on checking web devs found each of 4 buttons,value of passed in props.ind method 4,i.e value of after final increment.
finally fixed it.so var variable. each of 4 buttons stored in button array, value of wasn't copied in prop.ind(i) method parameter instead reference stored.hence last value of @ end of loop i.e 4 each of html button,props.ind(4).
now instead when declare let in loop refernce cannot stored since wont accessible outside of loop result immediate value of stored in props.ind.ie props.ind(0) 1st button , props.ind(1) 2nd button in way.
Comments
Post a Comment