14
common/resources/client/utils/hooks/use-linkified-string.ts
Executable file
14
common/resources/client/utils/hooks/use-linkified-string.ts
Executable file
@@ -0,0 +1,14 @@
|
||||
import {useMemo} from 'react';
|
||||
import linkifyStr from 'linkify-string';
|
||||
|
||||
export function useLinkifiedString(text: string | null | undefined) {
|
||||
return useMemo(() => {
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
return linkifyStr(text, {
|
||||
nl2br: true,
|
||||
attributes: {rel: 'nofollow'},
|
||||
});
|
||||
}, [text]);
|
||||
}
|
||||
Reference in New Issue
Block a user