shunjizhan / react-folder-tree

A versatile react treeview library that supports custom icons and event handlers
https://www.npmjs.com/package/react-folder-tree
119 stars 46 forks source link

How to rename file when adding new file. #71

Open damquanghieu opened 2 years ago

damquanghieu commented 2 years ago

I want to change the default name when creating a new file. For example "new page" I want to use for new functionality. Thanks very much

shunjizhan commented 2 years ago

ooooops seems we don't have a way to do that, sorry about it, but seems like a great FR for the next version

damquanghieu commented 2 years ago

ooooops seems we don't have a way to do that, sorry about it, but seems like a great FR for the next version

Is there any way I can do it for example overriding something?

shunjizhan commented 2 years ago

one hack way is to fork and change this line https://github.com/shunjizhan/react-folder-tree/blob/master/src/components/EditableName/EditableName.jsx#L56 so that when it sees the default name, it display what you need

shunjizhan commented 2 years ago

something like

{ name === DEFAULT_NAME ? 'new page' : name }
damquanghieu commented 2 years ago

something like

{ name === DEFAULT_NAME ? 'new page' : name }

Thanks so much.

damquanghieu commented 2 years ago

image This feature. I have a problem trying to set setTreeState from a data from the api in useEffect(), But my application was looping infinitely. Can you tell me the best way to set initState from the result of an api and not a sample data like testData?

image My code will look like this

ErnestoLopez commented 1 year ago

hello,

The same thing happens to me, if I update the data property with a state like you do, specifically when I add a folder, it gets into an infinite loop because every time I update as you do with "setTreeState" it re-identifies the event " addNode" and repeat the cycle.

Did you know how to fix it?

Thank you.

Ernesto

ErnestoLopez commented 1 year ago

I fixed it using a new state

` const handle_FolderTree_onTreeStateChange = async (state: object, event: any) => {

    if (stateHandlingEvent == true) {
        setStateHandlingEvent(false);
        }
    else {
        setStateHandlingEvent(true);
        const result = await FolderTree_onTreeStateChange(state, event);
        }
    }

`