is there a better way to write this code? - SolidJS