Refer to the official examples repository.
@SHAWO I’ve looked at your code a bit and it is off-topic.
It is not inserting a component instance using a tool, and should have been in it’s own topic rather than reviving this topic after 2 years.
All this said, I previously posted a complete example Instance DragTool here …
Draw model while moving mouse in custom tool - #11 by DanRathbun