Quiero pasar un valor del archivo A a una función en el archivo B que cambia con la entrada del control deslizante. Estoy tratando de hacer esto pasando el valor como accesorio.
Actualmente recibo el error "Se esperaban 1 argumentos, pero obtuve 0". cuando llamo a GraphArrayFunction() en el archivo B porque no estoy pasando un accesorio a través de la función. ¿Cómo pasaría un accesorio a través de la función si quiero que el accesorio pueda cambiarse? Presentar un:
const test = Number(rangeValue); GraphArrayFunction({test});Archivo B:
interface MainProps { test: number } export const GraphArrayFunction = (props: MainProps) => { const {test} = props; let i = test const j = 1; const graphArray = []; //let user change i if (i > 1) { while (j < i + 1){ graphArray.push(randomNumber()); j++; } } return graphArray; } const Graph = () => { return ( <Wrapper> <GraphOutline> {GraphArrayFunction().map((numbers, index) => <HeightBars height={numbers} />)} </GraphOutline> </Wrapper> ) } export default GraphPresentar un:
const test = Number(rangeValue); // Here you are passing {test} as an argument of function so it will work here. GraphArrayFunction({test});Archivo B:
interface MainProps { test: number } export const GraphArrayFunction = (props) => { const {test} = props; let i = test const j = 1; const graphArray = []; //let user change i if (i > 1) { while (j < i + 1){ graphArray.push(randomNumber()); j++; } } return graphArray; } // Error you are getting from this Graph function as you are calling above function here as well const Graph = () => { return ( <Wrapper> <GraphOutline> // here you are not passing any argument. I have passes test:15 and your // function will use this. And that's why you are getting error that function // should have at least one argument {GraphArrayFunction({test:15}).map((numbers, index) => <HeightBars height={numbers} />)} </GraphOutline> </Wrapper> ) } export default Graph