|
| 1 | +# Embed Apps in NEXT.JS |
| 2 | + |
| 3 | +### Native embedding in your NEXT.JS -based Web App |
| 4 | + |
| 5 | +First, install the Lowcoder SDK. Lowcoder publishes with every Version Release, a new version of Lowcoder SDK too. [https://www.npmjs.com/package/lowcoder-sdk](https://www.npmjs.com/package/lowcoder-sdk) |
| 6 | + |
| 7 | +yarn: |
| 8 | + |
| 9 | +``` |
| 10 | +yarn add lowcoder-sdk |
| 11 | +``` |
| 12 | + |
| 13 | +npm: |
| 14 | + |
| 15 | +``` |
| 16 | +npm install lowcoder-sdk |
| 17 | +``` |
| 18 | + |
| 19 | +### Integrate a Lowcoder App or Module into your existing app |
| 20 | + |
| 21 | +1. Publish your app/module in Lowcoder. |
| 22 | +2. Set the app/module's access privilege as public. |
| 23 | +3. Add code in your existing app as below. |
| 24 | + |
| 25 | +### Import CSS Styles |
| 26 | + |
| 27 | +``` |
| 28 | +import "lowcoder-sdk/dist/style.css"; |
| 29 | +``` |
| 30 | + |
| 31 | +### Embed Lowcoder Apps |
| 32 | + |
| 33 | +* Create Wrapper Component to Embed Lowcoder Apps |
| 34 | + |
| 35 | +```` |
| 36 | +``` |
| 37 | +"use client" |
| 38 | +import { LowcoderAppView } from "lowcoder-sdk"; |
| 39 | +
|
| 40 | +function LowcoderAppWrapper(props) { |
| 41 | + const { appId } = props; |
| 42 | + return ( |
| 43 | + <section style={{marginTop: '2rem'}}> |
| 44 | + <div style={{ |
| 45 | + display: 'flex', |
| 46 | + justifyContent: 'space-between', |
| 47 | + alignItems: 'center', |
| 48 | + }}> |
| 49 | + <h1>Lowcoder App</h1> |
| 50 | + </div> |
| 51 | + <LowcoderAppView |
| 52 | + appId={appId} |
| 53 | + /> |
| 54 | + </section> |
| 55 | + ) |
| 56 | +} |
| 57 | +
|
| 58 | +export default LowcoderAppWrapper; |
| 59 | +``` |
| 60 | +```` |
| 61 | + |
| 62 | +* Dynamically import the LowcoderAppWrapper component in the file where you want to embed the Lowcoder app |
| 63 | + |
| 64 | +```` |
| 65 | +``` |
| 66 | +const LowcoderAppWrapper = dynamic( |
| 67 | + () => import('../components/LowcoderAppWrapper'), {ssr: false} |
| 68 | +); |
| 69 | +``` |
| 70 | +```` |
| 71 | + |
| 72 | +* Now, we can embed our Lowcoder app by just passing the appId to the imported LowcoderAppWrapper component. |
| 73 | + |
| 74 | +```` |
| 75 | +``` |
| 76 | +<LowcoderAppWrapper |
| 77 | + appId='66ab6af10390b00771b2e649' |
| 78 | +/> |
| 79 | +``` |
| 80 | +```` |
| 81 | + |
| 82 | +### Embed Lowcoder Modules |
| 83 | + |
| 84 | +* Create Wrapper Component to Embed Lowcoder Modules |
| 85 | + |
| 86 | +```` |
| 87 | +``` |
| 88 | +"use client" |
| 89 | +import { useRef } from "react"; |
| 90 | +import { LowcoderAppView } from "lowcoder-sdk"; |
| 91 | +
|
| 92 | +function LowcoderModuleWrapper(props) { |
| 93 | + const { appId } = props; |
| 94 | + const appRef = useRef(); |
| 95 | + return ( |
| 96 | + <section style={{marginTop: '2rem'}}> |
| 97 | + <div style={{ |
| 98 | + display: 'flex', |
| 99 | + justifyContent: 'space-between', |
| 100 | + alignItems: 'center', |
| 101 | + }}> |
| 102 | + <h1>Lowcoder Module</h1> |
| 103 | + <button |
| 104 | + type="button" |
| 105 | + onClick={() => { |
| 106 | + appRef?.current?.invokeMethod("ShowNotification") |
| 107 | + }} |
| 108 | + > |
| 109 | + Invoke module method |
| 110 | + </button> |
| 111 | + </div> |
| 112 | + <LowcoderAppView |
| 113 | + ref={appRef} |
| 114 | + appId={appId} |
| 115 | + |
| 116 | + /> |
| 117 | + </section> |
| 118 | + ) |
| 119 | +} |
| 120 | +
|
| 121 | +export default LowcoderModuleWrapper; |
| 122 | +``` |
| 123 | +```` |
| 124 | + |
| 125 | +* Dynamically import the LowcoderModuleWrapper component in the file where you want to embed the Lowcoder Module |
| 126 | + |
| 127 | +```` |
| 128 | +``` |
| 129 | +const LowcoderModuleWrapper = dynamic( |
| 130 | + () => import('../components/LowcoderModuleWrapper'), {ssr: false} |
| 131 | +); |
| 132 | +``` |
| 133 | +```` |
| 134 | + |
| 135 | +* Now, we can embed our Lowcoder module by just passing the appId to the imported LowcoderModuleWrapper component. |
| 136 | + |
| 137 | +```` |
| 138 | +``` |
| 139 | +<LowcoderModuleWrapper |
| 140 | + appId="660f13367c18a91b174fe96d" |
| 141 | +/> |
| 142 | +``` |
| 143 | +```` |
| 144 | + |
| 145 | +### Properties |
| 146 | + |
| 147 | +| Name | Type | Description | Default value | |
| 148 | +| ---------------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------- | |
| 149 | +| appId | string | The app's id is required! | -- | |
| 150 | +| baseUrl | string | The api base url of the Lowcoder Instance. | https://api-service.lowcoder.cloud | |
| 151 | +| onModuleEventTriggered | (eventName: string) => void | (Only for Modules) Triggered when module's custom event is triggered. Works only when the app is a module. | -- | |
| 152 | +| onModuleOutputChange | (output: any) => void | (Only for Modules) Triggered when module's outputs change. Works only when the app is a module. | -- | |
0 commit comments