react native中使用tailwind并配置自动补全

javascript 复制代码
import { View, Text } from 'react-native';
import tw from 'twrnc';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-white dark:bg-black`}>
    <Text style={tw`text-md text-black dark:text-white`}>Hello World</Text>
  </View>
);

当然也支持条件变量

javascript 复制代码
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');
// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

重要的来了!配置vscode的补全

参考自React Native - Tailwind CSS autocomplete in VSCode for twrnc package

补全插件还是用的Tailwind CSS IntelliSense,需要添加vscode的配置并手动新建两个空文件

在下图添加

新建一个空文件tailwind.config.js

然后就可以了

相关推荐
张元清3 小时前
React scrollIntoView + useRef:滚动到指定元素 (2026)
javascript·react.js
光影少年3 小时前
RN 常见性能问题:JS卡顿、UI卡顿、桥接通信耗时
前端·react native·react.js
资源大佬星 课it4 小时前
2020全新React教程全家桶实战redux+antd+React Hooks前端js视频
前端·javascript·react.js
名字还没想好☜1 天前
React 用自定义 useDebounce Hook 治好搜索框频繁请求:防抖、竞态取消与卸载清理
前端·javascript·react.js·react·hooks
淼澄研学1 天前
Python调用通义千问API实现长尾搜题内容自动化生成实战
前端·react.js·架构
张元清1 天前
React useSessionStorage Hook:刷新不丢、只属于当前标签页的状态 (2026)
前端·javascript·react.js
拾年2752 天前
React Hooks 进阶篇:useMemo / useCallback / useReducer / useImperativeHandle,用「算账 +
前端·javascript·react.js
拾年2752 天前
React Hooks 保姆级教程:把组件想象成失忆的打工人,4 个 Hook 带你原地起飞
前端·javascript·react.js
小林ixn2 天前
在浏览器里跑 DeepSeek-R1:WebGPU + Transformers.js 实战
react.js·llm·浏览器
光影少年2 天前
react navite性能优化 & 常见坑
前端·react native·掘金·金石计划