Dynamic color meshStandardMaterial in instancedMesh

<instancedMesh ref={ref} args={[null, null, blocks.length]}>
    <boxBufferGeometry attach="geometry" args={[1, 1, 1]}>

    <meshStandardMaterial attach="material" ref={material}>


I want to set the color for the cube depending on its position, I figured out how to use boxBufferGeometry in instancedMesh, however I don’t understand how to do it with meshStandardMaterial and color

const ref = useRef<Mesh>()
const material = useRef<MeshStandardMaterial>()
useLayoutEffect(() => {
  blocks.forEach((v, i) => {
    tempObject.position.set(v.x, v.y, v.z)
    ref.current.setMatrixAt(i, tempObject.matrix)
    ref.current.instanceMatrix.needsUpdate = true
}, [])

You can set the color by using setColorAt method
ref.current.setColorAt(index, new THREE.Color(color))